using System.Collections;
using System.IO;
using System;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.Utils;
//using System.Data.OleDb.OleDbCommandBuilder;//JMR -- DEV -- commented out
using System.Data.OleDb;//JMR -- DEV -- added
//using System.Data.Common.DbCommandBuilder;//JMR -- DEV -- commented out
using System.Data.Common;//JMR -- DEV -- added
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
//using System.Object;//JMR -- DEV -- commented out
//using System;//JMR -- DEV -- added
//using System.MarshalByRefObject;//JMR -- DEV -- commented out
//using System.ComponentModel.Component;//JMR -- DEV -- commented out
//using System.ComponentModel;//JMR -- DEV -- added
//using System.Data.OleDb;
using DevExpress.XtraReports.UI;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraEditors;
using System.Xml;
using System.Xml.Schema;
using System.Linq;//JMR used for source.Count()


namespace ePlanSysOman
{
  public partial class frmMKPL
  {
      
    string PLANNUMBER = "";
    public bool m_Success = false;
    string KCKLA = "";
    public int KCLFROM = 0;
    public DataSet dssch2 = new DataSet();

    private void  // ERROR: Handles clauses are not supported in C#
frmKcl_Load(object sender, System.EventArgs e)
    {
      DataSet DSA = new DataSet();
      clsData DCA = new clsData();
      DSA = DCA.getData("SELECT * FROM TBLTAIL");
      this.FillCountryTail();
      DSA = DCA.getData("SELECT DISTINCT GENPDF2 FROM TBLgENERAL");
      for (int I = 0; I <= DSA.Tables[0].Rows.Count - 1; I++) {
        cmbECP.Properties.Items.Add(DSA.Tables[0].Rows[I][0]);
      }
    }
    private void FillCountryTail()
    {
      DataSet aset = new clsData().getData("select * from tblTail order by tlSerial");
      int count = aset.Tables[0].Rows.Count;
      int num3 = (count - 1);
      int i = 0;
      while ((i <= num3)) {
        ImageComboBoxItem item = new ImageComboBoxItem {
          Value = aset.Tables[0].Rows[i]["tlTypeVer"] + " -" + aset.Tables[0].Rows[i]["tlNumber"] + "  ( " + aset.Tables[0].Rows[i]["tlSerial"] + " )",
          Description = Conversions.ToString(aset.Tables[0].Rows[i]["tlNumber"])
        };
        this.cmbTail.Properties.Items.Add(item);
        i += 1;
      }
      aset.Dispose();
      aset = null;
    }

    private void  // ERROR: Handles clauses are not supported in C#
GridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
    {
      //If e.Column.FieldName = "AI" Then
      //    If e.RowHandle = -999997 Then
      //    Else
      //        e.DisplayText = e.RowHandle + 1.ToString
      //    End If

      //End If
    }

    private void  // ERROR: Handles clauses are not supported in C#
GridView1_CustomRowFilter(object sender, DevExpress.XtraGrid.Views.Base.RowFilterEventArgs e)
    {
      //Dim view As GridView = CType(sender, GridView)
      //Dim rowHandle As Integer = view.GetRowHandle(e.ListSourceRow)
      //e.Visible = Not view.IsMasterRowEmptyEx(rowHandle, view.GetRelationIndex(rowHandle, "Level3"))


      //e.Handled = True
    }




    private void  // ERROR: Handles clauses are not supported in C#
GridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
    {


      // End If

    }

    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton1_Click(System.Object sender, System.EventArgs e)
    {
      xrMKPL XR = new xrMKPL();

      XR.grdKCL.DataSource = GridControl1.DataSource;
      XR.txtDate.Text = DateAndTime.DateString;//JMR
      XR.XrTableCell4.Text = "MKPL EXPORT FOR - " + Module1.newModule.KCLTV + " : " + KCLFROM + " TO " + Module1.newModule.KCLENDS;
      XR.txtType.Text = Module1.newModule.KCLTV + " : " + KCLFROM + " TO " + Module1.newModule.KCLENDS;
      XR.txtTailNo.Text = Module1.newModule.TailNo;
      XR.txtCountry.Text = frmMain.start.txtCountry.Text;
      XR.txtProgram.Text = frmMain.start.cmbProgram.Text;

      if (Module1.newModule.RELAS == true)
      {
      } else {
        XR.RELDA = KCKLA;
      }

      XR.ShowPreview();
    }

    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton2_Click(System.Object sender, System.EventArgs e)
    {
      clsData data = new clsData();
      DataSet aset = new DataSet();
      DataSet aset2 = new DataSet();
      DataSet ASET3 = new DataSet();
      DataSet dataSet = new DataSet();
      DataSet set2 = new DataSet();
      DataSet set3 = new DataSet();
      frmSearch search = new frmSearch();
      int QTYP;
      string QTYSTR;
      DataRow[] source;
      string expor;
      string KCLK = "";//JMR -- nulled it
      string QTYYPSTR = "";//JMR -- nulled it
      string KLCK3;
      expor = Guid.NewGuid().ToString();
      bool relasA = false;
      DialogResult ans;
      Module1.newModule.RELAS = false;

      ans = MessageBox.Show("    KIT CONTENT LIST" + System.Environment.NewLine + "       (AUTHORIZED)", "KCL", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
        //JMR changed Windows.Forms.DialogResult.Yes to DialogResult.Yes
      if (ans == DialogResult.Yes) {
        GridControl1.DataSource = null;
        GridControl1.RefreshDataSource();
        relasA = true;
        data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='-' WHERE ((PRTKCL='')OR (PRTKCL IS NULL))");
        data.ExecuteSQL("UPDATE tblgeneral SET genpdf2 ='-' WHERE ((genpdf2='')OR (genpdf2 IS NULL))");
      } else {
        return;
      }
        //JMR
        aset = data.getData(string.Concat(new string[] {
        "select distinct prtPartNumberDoc from tblAssembly where prtKCL like '%?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "%' AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='",
        Module1.newModule.KCLTV,
        "'and ",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "
      }));
      aset.Tables[0].Columns.Add("NOMENCLATURE");
      aset.Tables[0].Columns.Add("QTY");
      aset.Tables[0].Columns.Add("COUNTTYPE");//JMR
      aset.Tables[0].Columns.Add("RELDATE");
      for (int kl = 0; kl <= aset.Tables[0].Rows.Count - 1; kl++) {
        string partns;

        frmMain.start.spr1.Maximum = aset.Tables[0].Rows.Count - 1;
        frmMain.start.spr1.Value = kl;
        frmMain.start.spr1.ProgressBar.Refresh();
        pr1.Properties.Maximum = aset.Tables[0].Rows.Count - 1;
        pr1.EditValue = kl;
        pr1.Refresh();
        QTYP = 0;
        partns = aset.Tables[0].Rows[kl]["prtPartNumberDoc"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          //JMR
        aset2 = data.getData(string.Concat(new string[] {
          "select  prtPartNumberDoc,prtDescription,prtQty,prtInit,prtKCL from tblAssembly where ((PRTKCL <>'') OR (PRTKCL IS NOT NULL) OR(prtKCL like '%?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "%')) AND  prtaction ='ADD'  and prtPartNumberDoc='" + partns + "'  and ((prtTypeVer ='",
          Conversions.ToString(Module1.newModule.KCLTV),
          "'and ",
          Conversions.ToString(Module1.newModule.KCLENDS),
          " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) order by prtPartNumberDoc "
        }));
        string NOMEN = "";//JMR -- nulled it
        string INITF = "";//JMR -- nulled it

        for (int KL2 = 0; KL2 <= aset2.Tables[0].Rows.Count - 1; KL2++) {
          if (object.ReferenceEquals(aset2.Tables[0].Rows[KL2]["prtInit"], DBNull.Value)) {
            INITF = "C";

          } else {
              INITF = aset2.Tables[0].Rows[KL2]["prtInit"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          }
          KCLK = aset2.Tables[0].Rows[KL2]["prtKcl"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          KLCK3 = KCLK;
          KCKLA = KCLK;
          NOMEN = aset2.Tables[0].Rows[KL2]["prtDescription"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          if (NOMEN == "COAX") {
            NOMEN = "CABLE ASSEMBLY";
          } else if (NOMEN == "HARNESS") {
            NOMEN = "WIRING HARNESS ASSEMBLY";
          }
          QTYSTR = aset2.Tables[0].Rows[KL2]["prtQty"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          if (QTYSTR.Contains("IN")) {
            QTYSTR = QTYSTR.Substring(0, QTYSTR.IndexOf("IN")).Trim();
            QTYP = QTYP + Conversions.ToInteger(QTYSTR);
            QTYYPSTR = Conversions.ToString(QTYP) + " IN";
          } else if (QTYSTR.Contains("REF")) {
            QTYYPSTR = QTYSTR;
          } else if (QTYSTR.Contains("a")) {
            QTYYPSTR = QTYSTR;
          } else if (QTYSTR.Contains("A")) {
            QTYYPSTR = QTYSTR;
          } else {
            QTYP = QTYP + Conversions.ToInteger(QTYSTR);
            QTYYPSTR = Conversions.ToString(QTYP);
          }

        }
        try {
          int num5;
          DataRow row7;
          DataRow[] rowArray7;
          source = aset.Tables[0].Select(("prtPartNumberDoc ='" + partns + "'"));

          int num321 = (source.Count() - 1);
          num5 = 0;
          while ((num5 <= num321)) {
            row7 = source[num5];
            row7[2] = QTYYPSTR;
            row7[1] = NOMEN;
            row7[3] = INITF;
            row7[4] = KCLK;
            num5 += 1;
          }

        } catch (Exception ex) {

        }

      }

      ASET3 = data.getData(string.Concat(new string[] {
        "select distinct prtPartNumberDoc from tblAssembly where ((prtKCL NOT like '%?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "%') or (prtKCL is null))  AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='",
        Module1.newModule.KCLTV,
        "'and ",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "
      }));
      if (ASET3.Tables[0].Rows.Count == 0) {
        //KCLK = KCLK;  //not necessary
        KCKLA = KCLK;
      } else {
        if (relasA == false) {
          KCLK = "";
        } else {
          if (aset.Tables[0].Rows.Count == 0) {
            KCKLA = "456";
            KCLK = "?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "^" + DateAndTime.DateString + expor + "!";
          } else {
              KCLK = "?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "^" + DateAndTime.DateString + expor + "!";
            KCKLA = KCLK;
          }

        }


        try {
          aset.Tables[0].Columns.Add("NOMENCLATURE");
          aset.Tables[0].Columns.Add("QTY");
          aset.Tables[0].Columns.Add("COUNTTYPE");
          aset.Tables[0].Columns.Add("RELDATE");

        } catch (Exception ex) {

        }

        for (int kl = 0; kl <= ASET3.Tables[0].Rows.Count - 1; kl++) {
          string partns;

          frmMain.start.spr1.Maximum = ASET3.Tables[0].Rows.Count - 1;
          frmMain.start.spr1.Value = kl;
          frmMain.start.spr1.ProgressBar.Refresh();
          pr1.Properties.Maximum = ASET3.Tables[0].Rows.Count - 1;
          pr1.EditValue = kl;
          pr1.Refresh();
          QTYP = 0;

          partns = ASET3.Tables[0].Rows[kl]["prtPartNumberDoc"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          aset2 = data.getData(string.Concat(new string[] {
            "select  prtPartNumberDoc,prtDescription,prtQty,prtInit,prtKCL from tblAssembly WHERE prtaction ='ADD'  and prtPartNumberDoc='" + partns + "'  and ((prtTypeVer ='",
            Module1.newModule.KCLTV,
            "'and ",
            Conversions.ToString(Module1.newModule.KCLENDS),
            " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='",
            Module1.newModule.KCLTV,
            "' and (",
            Conversions.ToString(Module1.newModule.KCLENDS),
            " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc"
          }));
          string NOMEN = "";//JMR -- nulled it;
          string INITF = "";//JMR -- nulled it
          string OLDKCL;
          string NEWKCL;
          string OLDKCL2;
          try {

          } catch (Exception ex) {

          }
          for (int KL2 = 0; KL2 <= aset2.Tables[0].Rows.Count - 1; KL2++) {
            if (object.ReferenceEquals(aset2.Tables[0].Rows[KL2]["prtInit"], DBNull.Value)) {
              INITF = "C";

            } else {
                INITF = aset2.Tables[0].Rows[KL2]["prtInit"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
            }
            // KCLK = aset2.Tables(0).Rows(KL2).Item("prtKcl")
            NOMEN = aset2.Tables[0].Rows[KL2]["prtDescription"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
            if (NOMEN == "COAX") {
              NOMEN = "CABLE ASSEMBLY";
            } else if (NOMEN == "HARNESS") {
              NOMEN = "WIRING HARNESS ASSEMBLY";
            }
            QTYSTR = aset2.Tables[0].Rows[KL2]["prtQty"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
            if (QTYSTR.Contains("IN")) {
              QTYSTR = QTYSTR.Substring(0, QTYSTR.IndexOf("IN")).Trim();
              QTYP = QTYP + Conversions.ToInteger(QTYSTR);//JMR
              QTYYPSTR = Conversions.ToString(QTYP) + " IN";
            } else if (QTYSTR.Contains("REF")) {
              QTYYPSTR = QTYSTR;
            } else if (QTYSTR.Contains("A")) {
              QTYYPSTR = QTYSTR;
            } else if (QTYSTR.Contains("a")) {
              QTYYPSTR = QTYSTR;
            } else {
              QTYP = QTYP + Conversions.ToInteger(QTYSTR);//JMR
              QTYYPSTR = Conversions.ToString(QTYP);
            }


          }
          try {
            int num5;
            DataRow row7;
            DataRow[] rowArray7;
            source = aset.Tables[0].Select(("prtPartNumberDoc ='" + partns + "'"));

            int num321 = (source.Count() - 1);
            num5 = 0;
            if (num321 == -1) {
              aset.Tables[0].Rows.Add(partns, NOMEN, QTYYPSTR, INITF, KCLK);
              for (int KL2 = 0; KL2 <= aset2.Tables[0].Rows.Count - 1; KL2++) {
                if (relasA == true) {
                    OLDKCL = aset2.Tables[0].Rows[KL2]["prtKCL"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
                    //JMR
                  if (OLDKCL.Contains("?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS)))
                  {
                    OLDKCL2 = OLDKCL;
                    OLDKCL = OLDKCL.Replace(OLDKCL.Substring(OLDKCL.IndexOf("?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "^"), KCLK.Length), KCLK);
                    NEWKCL = OLDKCL;
                  } else {
                    OLDKCL2 = OLDKCL;
                    NEWKCL = OLDKCL + KCLK;
                  }
                  data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='" + NEWKCL + "' WHERE PRTKCL ='" + OLDKCL2 + "' AND PRTPARTNUMBERDOC ='" + partns + "' and ((prtTypeVer ='" + Module1.newModule.KCLTV + "'and " + Module1.newModule.KCLENDS + " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='" + Module1.newModule.KCLTV + "' and (" + Module1.newModule.KCLENDS + " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%')))");
                }
              }


            } else {
              while ((num5 <= num321)) {
                row7 = source[num5];
                row7[2] = QTYYPSTR;
                row7[1] = NOMEN;
                row7[4] = KCLK;
                row7[3] = INITF;
                num5 += 1;
              }
            }

            //If relasA = True Then
            //    data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='" & DateString & "' WHERE PRTPARTNUMBERDOC ='" & partns & "' and ((prtTypeVer ='" & KCLTV & "'and " & KCLENDS & " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='" & KCLTV & "' and (" & KCLENDS & " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%')))")
            //End If

            num5 += 1;


          } catch (Exception ex) {

          }

        }


      }
      DataSet aset4 = new DataSet();
      
      aset4 = data.getData(string.Concat(new string[] {
        "SELECT * FROM TBLGENERAL WHERE ((genPlannumber LIKE '30%') OR (genPlannumber LIKE '50%')) AND GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' )) order by  genPlannumber"
      }));
      if (ASET3.Tables[0].Rows.Count == 0) {
        if (aset.Tables[0].Rows.Count == 0) {
          KCKLA = "456";
          KCLK = "?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "^" + DateAndTime.DateString + expor + "!";
        } else {
            KCLK = "?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "^" + DateAndTime.DateString + expor + "!";
          KCKLA = KCLK;
        }
      } else {

      }





      for (int kl3 = 0; kl3 <= aset4.Tables[0].Rows.Count - 1; kl3++) {
        string harnesnumb = null;
        string tbd = null;
        string kld = null;
        string CKLS = null;
        string cnO = null;
        string PLCAID = null;
        string OLDKCL2 = null;
        frmMain.start.spr1.Maximum = aset4.Tables[0].Rows.Count - 1;
        frmMain.start.spr1.Value = kl3;
        frmMain.start.spr1.ProgressBar.Refresh();
        pr1.Properties.Maximum = aset4.Tables[0].Rows.Count - 1;
        pr1.EditValue = kl3;
        pr1.Refresh();
        cnO = aset4.Tables[0].Rows[kl3]["genPlannumber"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        PLCAID = aset4.Tables[0].Rows[kl3]["genPlId"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        harnesnumb = aset4.Tables[0].Rows[kl3]["genPartsNote"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        if (harnesnumb.Contains("OBTAIN WIRES FROM LWA : ______")) {
        } else if (harnesnumb.Contains("NO LWA")) {

        } else {
          tbd = harnesnumb.Substring(23, 9).Trim();
          if (tbd.Contains("-")) {
            tbd = tbd.Substring(0, tbd.Length - 1);
          } else if (tbd.Contains(".")) {
            tbd = tbd.Substring(0, tbd.Length - 1);
          } else {

          }
          kld = aset4.Tables[0].Rows[kl3]["genPdf2"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
          if (kld == "-") {
            CKLS = KCLK;
          } else {
            if (kld.Contains("?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS))) {
              OLDKCL2 = kld;
              kld = kld.Replace(kld.Substring(kld.IndexOf("?" + Module1.newModule.KCLTV + Conversions.ToString(Module1.newModule.KCLENDS) + "^"), KCLK.Length), KCLK);
              CKLS = kld;
            } else {
              OLDKCL2 = kld;
              CKLS = kld + KCLK;
            }

          }
          string RERBD = null;

          string RERBD1 = null;
          string RERBD2 = null;
          string RERBD3 = null;
          if (object.ReferenceEquals(aset4.Tables[0].Rows[kl3]["GENPdf1"], DBNull.Value))
          {
            RERBD = "TBD";
            tbd = tbd + "-" + RERBD;
            try {
              aset.Tables[0].Rows.Add(tbd, "LOOSE WIRE ASSEMBLY", "1", "C", CKLS);
            } catch (Exception ex) {

            }

          } else {
              RERBD = aset4.Tables[0].Rows[kl3]["GENPdf1"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
            if (RERBD.Contains(",")) {
              string TBD2;
              TBD2 = tbd;
              RERBD3 = RERBD.Substring(0, RERBD.IndexOf(",")).Trim();
              tbd = TBD2 + "-" + RERBD3;
              try {
                aset.Tables[0].Rows.Add(tbd, "LOOSE WIRE ASSEMBLY", "1", "C", CKLS);
              } catch (Exception ex) {

              }

              RERBD1 = RERBD.Substring(RERBD.IndexOf(",") + 1).Trim();
              if (RERBD1.Contains(",")) {
                RERBD2 = RERBD1.Substring(RERBD.IndexOf(",") + 1).Trim();
                tbd = TBD2 + "-" + RERBD2;
                try {
                  aset.Tables[0].Rows.Add(tbd, "LOOSE WIRE ASSEMBLY", "1", "C", CKLS);
                } catch (Exception ex) {

                }
              } else {
                tbd = TBD2 + "-" + RERBD1;
                try {
                  aset.Tables[0].Rows.Add(tbd, "LOOSE WIRE ASSEMBLY", "1", "C", CKLS);
                } catch (Exception ex) {

                }
              }

            } else {
              tbd = tbd + "-" + RERBD;

              try {
                aset.Tables[0].Rows.Add(tbd, "LOOSE WIRE ASSEMBLY", "1", "C", CKLS);
              } catch (Exception ex) {

              }
            }
          }


          try {
            data.ExecuteSQL("UPDATE tblgeneral SET genpdf2 ='" + CKLS + "' WHERE genPlId='" + PLCAID + " ' AND  genPlannumber = '" + cnO + "'");
          } catch (Exception ex) {

          }
        }


      }

      xrMKPL XR = new xrMKPL();
      GridControl1.DataSource = aset.Tables[0];
    }

    private void  // ERROR: Handles clauses are not supported in C#
cmbTail_SelectedIndexChanged(System.Object sender, System.EventArgs e)
    {

      clsData data = new clsData();
      frmCards frm = new frmCards();


      Module1.newModule.KCLTV = this.cmbTail.Text;


      Module1.newModule.AreaNo = 0;
      string endtyp = "";


    }

    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton3_Click(System.Object sender, System.EventArgs e)
    {
      ListBoxControl1.SendToBack();
      GridControl1.RefreshDataSource();
      DataSet dssch = new DataSet();
      clsData data = new clsData();
      DataRow ROW;
      DataSet aset = new DataSet();
      DataSet aset2 = new DataSet();
      DataSet ASET3 = new DataSet();
      DataSet dataSet = new DataSet();
      DataSet set2 = new DataSet();
      DataSet set3 = new DataSet();
      frmSearch search = new frmSearch();
      int QTYP = 0;
      string QTYSTR = null;
      DataRow[] source;
      string expor;
      string KCLK = null;
      int IJK = 0;

      dsSchema.Clear();
      Module1.newModule.QN = 0;
      Module1.newModule.QR = 0;
      Module1.newModule.Qseg = "";
      dssch.Reset();

      try
      {
          dssch.ReadXmlSchema(Application.StartupPath + "/SAPSchema.xsd");
      }
        catch(Exception ex)
      {
          MessageBox.Show(ex.Message, "error");
      }
      try
      {
          dssch.Tables["NHA"].Columns.Remove("NHA_DWG_DESCRIPTION");
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.Message, "error");
      }
      dssch.Tables["LWA_PARTS"].Columns.Remove("DWG_ZONE");
      dssch.Tables["LWA_PARTS"].Columns.Remove("DRAWINGS_ID");
      if (cmbTail.Text == "") {
        XtraMessageBox.Show("Please select a T/V", "MKPL");
        return;
      }
      if (ComboBoxEdit1.Text == "") {
        XtraMessageBox.Show("Please select FROM", "MKPL");
        return;
      }
      if (ComboBoxEdit2.Text == "") {
        XtraMessageBox.Show("Please select TO", "MKPL");
        return;
      }

      Module1.newModule.KCLENDS = Conversions.ToInteger(ComboBoxEdit2.Text);//JMR
      KCLFROM = Conversions.ToInteger(ComboBoxEdit1.Text);//JMR

      string QTYYPSTR = null;
      expor = Guid.NewGuid().ToString();
      bool relasA = false;
      DialogResult ans;
      Module1.newModule.RELAS = false;
      ans = XtraMessageBox.Show("  Calculate MKPL Export", "MKPL", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
      if (ans == DialogResult.Yes) {


      } else {
        return;
      }

      dsSchema.Tables["ECP"].Rows.Add(cmbECP.Text, 1, Module1.newModule.KCLTV, KCLFROM, Module1.newModule.KCLENDS);
      dssch.Tables["ECP"].Rows.Add(cmbECP.Text, 1, Module1.newModule.KCLTV, KCLFROM, Module1.newModule.KCLENDS);

      aset = data.getData(string.Concat(new string[] {
        "select distinct(prtECP) from  tblAssembly where prtpartNumberDoc <>'' and prtaction <>'REINSTALL' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='",
        Module1.newModule.KCLTV,
        "'and ",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE genpdf2 ='" + cmbECP.Text + "' and GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' )))"
      }));

      try
      {
          if(aset.Tables.Count != 0)
          {              
            for (int kl = 0; kl <= aset.Tables[0].Rows.Count - 1; kl++)
              {
                dsSchema.Tables["NHA"].Rows.Add(aset.Tables[0].Rows[kl]["prtECP"], 1, kl + 1);
                dssch.Tables["NHA"].Rows.Add(aset.Tables[0].Rows[kl]["prtECP"], 1, kl + 1);
              }
          }
      }
      catch(Exception ex)  
      {
          MessageBox.Show(ex.Message, "ERROR");
      }

      aset = data.getData(string.Concat(new string[] {
        "select * from  tblAssembly where prtpartNumberDoc <>'' and prtaction <>'REINSTALL' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='",
        Module1.newModule.KCLTV,
        "'and ",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE genpdf2 ='" + cmbECP.Text + "' and GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "
      }));
      DataRow[] FOUNDROWS4;
      DataRow[] foundrows5;
      DataRow drt;


      if (aset.Tables.Count != 0)
      {
          IJK = aset.Tables[0].Rows.Count - 1;
      }
      for (int kl = 0; kl <= aset.Tables[0].Rows.Count - 1; kl++) {

        string drn = "";
        int nhan = 0;
        drn = aset.Tables[0].Rows[kl]["prtECP"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        FOUNDROWS4 = dsSchema.Tables["NHA"].Select(("NHA_DWG_NUM = '" + drn + "'"));
        drt = FOUNDROWS4[0];
        nhan = Conversions.ToInteger(drt["NHA_Id"]);//JMR -- look at -- converted it to Integer 
        foundrows5 = dsSchema.Tables["DRAWINGS"].Select(("DWG_NUM = '" + aset.Tables[0].Rows[kl]["prtECP"] + "-" + aset.Tables[0].Rows[kl]["prtDash"] + "'"));
        if (foundrows5.Count() == 0) {
          dsSchema.Tables["DRAWINGS"].Rows.Add(aset.Tables[0].Rows[kl]["prtECP"] + "-" + aset.Tables[0].Rows[kl]["prtDash"], aset.Tables[0].Rows[kl]["prtDash"], "", "", kl + 1, nhan);
          dssch.Tables["DRAWINGS"].Rows.Add(aset.Tables[0].Rows[kl]["prtECP"] + "-" + aset.Tables[0].Rows[kl]["prtDash"], aset.Tables[0].Rows[kl]["prtDash"], "", "", kl + 1, nhan);
        }


      }


      aset.Tables[0].Columns.Add("LENGTH");
      aset.Tables[0].Columns.Add("LOCATION");
      aset.Tables[0].Columns.Add("sort");
      aset.Tables[0].Columns.Add("LwaId");
      for (int t = 0; t <= aset.Tables[0].Rows.Count - 1; t++) {
        aset.Tables[0].Rows[t]["sort"] = aset.Tables[0].Rows[t]["prtEcp"] + "-" + aset.Tables[0].Rows[t]["prtDash"];
        aset.Tables[0].Rows[t]["LwaId"] = t + 1;
      }


      FOUNDROWS4 = aset.Tables[0].Select(("prtEcp <> ''"));
      int num49 = (FOUNDROWS4.Count() - 1);
      int i4 = 0;
      while ((i4 <= num49)) {

        drt = FOUNDROWS4[i4];
        drt[1] = drt[5] + "-" + drt[1];
        i4 = i4 + 1;

      }
      FOUNDROWS4 = aset.Tables[0].Select(("prtEcp <> ''"));
      num49 = (FOUNDROWS4.Count() - 1);
      i4 = 0;
      while ((i4 <= num49)) {
        int qtytotal = 0;
        string duppart = "";
        string qtystring = "";
        string qty2string = "";
        int qty1 = 0;
        int qty2 = 0;
        DataRow[] FOUNDROWStotal = null;//JMR -- DEV -- look at -- nulled it
        DataRow drtTotal;
        string totalDrwg = "";
        string totaldesc = "";
        string totalPLid = "";


        drt = FOUNDROWS4[i4];
        totalDrwg = drt[1].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        duppart = drt[3].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        qtystring = drt[2].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        if (qtystring == "AR") {
          qty1 = 9992;
        } else if (qtystring == "REF") {
          qty1 = 9992;
        } else {

          qty1 = Conversions.ToInteger(drt[2]);//JMR -- converted it to int
        }

        totaldesc = drt[4].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        totalPLid = drt[0].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
        try {
          FOUNDROWStotal = aset.Tables[0].Select("prtdash='" + totalDrwg + "' and prtPartNumberDoc ='" + duppart + "' and prtPlid<>'" + totalPLid + "' and prtDescription='" + totaldesc + "'");

        } catch (Exception ex) {

        }
        for (int g = 0; g <= FOUNDROWStotal.Count() - 1; g++) {
          try {
            drtTotal = FOUNDROWStotal[g];//JMR
            qty2string = drtTotal[2].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString
            if (qty2string == "AR") {
              qty1 = 9992;
              drt[2] = qty1;
              drtTotal[2] = 3333;
            } else {
              qty2 = Conversions.ToInteger(drtTotal[2]);//JMR -- converted it to integer
              drt[2] = qty1 + qty2;
              drtTotal[2] = 3333;
            }

          } catch (Exception ex) {

          }

        }

        //drt.Item(1) = drt.Item(5) & "-" & drt.Item(1)
        i4 = i4 + 1;

      }
      aset.Tables[0].AcceptChanges();

      FOUNDROWS4 = aset.Tables[0].Select("prtQty ='3333'");
      num49 = (FOUNDROWS4.Count() - 1);
      i4 = 0;
      while ((i4 <= num49)) {
        DataRow delrow;

        drt = FOUNDROWS4[i4];
        try {
          aset.Tables[0].Rows.Remove(drt);

        } catch (Exception ex) {

        }
        i4 = i4 + 1;

      }
      aset.AcceptChanges();

      for (int kl = 0; kl <= aset.Tables[0].Rows.Count - 1; kl++) {
        foundrows5 = dsSchema.Tables["DRAWINGS"].Select(("DWG_NUM = '" + aset.Tables[0].Rows[kl]["prtDash"] + "'"));
        drt = foundrows5[0];

        string drn = "";
        int nhan = 0;

        drn = drt["DWG_NUM"].ToString();//JMR -- look at -- added ToString() -- look at ToString vs Conversions.ToString

        nhan = Conversions.ToInteger(drt["DRAWINGS_Id"]);//JMR -- converted it to int
        int QTYU = 0;
        if (aset.Tables[0].Rows[kl]["prtQTY"] == "AR") {
          QTYU = 9998;
        } else {
          QTYU = Conversions.ToInteger(aset.Tables[0].Rows[kl]["prtQTY"]);//JMR -- converted it to int
        }


        dsSchema.Tables["PARTS"].Rows.Add(aset.Tables[0].Rows[kl]["prtPartNumberDoc"], aset.Tables[0].Rows[kl]["prtDescription"], aset.Tables[0].Rows[kl]["prtQTY"], "", aset.Tables[0].Rows[kl]["prtDwgZone"].ToString().Trim(), aset.Tables[0].Rows[kl]["prtAction"], nhan, kl + 1);//JMR-- chsnged trim() to ToString().Trim()
        dssch.Tables["PARTS"].Rows.Add(aset.Tables[0].Rows[kl]["prtPartNumberDoc"], aset.Tables[0].Rows[kl]["prtDescription"], QTYU, "", aset.Tables[0].Rows[kl]["prtDwgZone"].ToString().Trim(), aset.Tables[0].Rows[kl]["prtAction"], nhan, kl + 1);//JMR-- chsnged trim() to ToString().Trim()
        IJK = kl;
      }
      int ku = 0;
      foundrows5 = dsSchema.Tables["drawings"].Select("dwg_num<> ''");
      ku = IJK + 1;

      DataSet ASSYDS = new DataSet();
      ASSYDS = data.getData(string.Concat(new string[] {
        "select DISTINCT PRTECP from  tblAssembly where prtpartNumberDoc <>'' and prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='",
        Module1.newModule.KCLTV,
        "'and ",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE  GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where  (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Conversions.ToString(Module1.newModule.KCLENDS),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' AND genpdf2 =' " + cmbECP.Text + "')))  "
      }));

      for (int kl = 0; kl <= ASSYDS.Tables[0].Rows.Count - 1; kl++) {
        pr1.Properties.Maximum = ASSYDS.Tables[0].Rows.Count - 1;
        pr1.EditValue = kl;
        pr1.Refresh();
        string harnessname = "";
        DataSet dsMPRS = new DataSet();
        string drawingnum = "";
        drawingnum = ASSYDS.Tables[0].Rows[kl][0].ToString();

        dsMPRS = data.getData("SELECT * FROM MPRS WHERE (" + Module1.newModule.KCLENDS + " between int(fr0m) and int(thru)) and tv ='" + Module1.newModule.KCLTV + "' and DWG ='" + drawingnum + "' AND APP='A' AND NOMEN LIKE 'WIRIN%' AND PART_NUMBER NOT IN(SELECT prtPartNumberDoc as PART_NUMBER FROM TBLASSEMBLY WHERE PRTACTION ='ADD')");
        if (dsMPRS.Tables[0].Rows.Count != 0) {
          for (int hj = 0; hj <= dsMPRS.Tables[0].Rows.Count - 1; hj++) {
            try {
              harnessname = dsMPRS.Tables[0].Rows[hj][4].ToString().Trim();
            } catch (Exception ex) {

            }

            DataSet harnds = new DataSet();
            string sapPlid = "";
            harnds = data.getData("SELECT * FROM TBLSELHARNESS WHERE NEWHRN='" + harnessname + "'");
            try {
              sapPlid = harnds.Tables[0].Rows[0][0].ToString();
              ku = IJK + 2;
              IJK = IJK + 2;
            } catch (Exception ex) {

            }
            string HARNESSSYNTH = "'";
            DataSet SYNTHDS = new DataSet();
            SYNTHDS = data.getData("SELECT * FROM TBLGENERAL WHERE GENPLID ='" + sapPlid + "'");
            if (SYNTHDS.Tables[0].Rows.Count == 0) {

            } else {
              try {
                HARNESSSYNTH = SYNTHDS.Tables[0].Rows[0]["genPdf1"].ToString();
                HARNESSSYNTH = harnessname.Substring(0, harnessname.IndexOf("-")) + "-" + HARNESSSYNTH;
              } catch (Exception ex) {
                HARNESSSYNTH = harnessname.Substring(0, harnessname.IndexOf("-")) + "-TBD";
              }

            }

            string drn = "";
            int nhan = 0;
            foundrows5 = dsSchema.Tables["DRAWINGS"].Select(("DWG_NUM = '" + drawingnum + "-" + Conversions.ToString(dsMPRS.Tables[0].Rows[0][3]) + "'"));
            if (foundrows5.Count() == 0) {
              foundrows5 = dsSchema.Tables["NHA"].Select("NHA_DWG_NUM ='" + drawingnum + "'");


              int MAXNHA = 0;
              MAXNHA = Conversions.ToInteger(foundrows5[0][2]);
              foundrows5 = dsSchema.Tables["drawings"].Select("dwg_num<> ''");
              int MAXDWG = 0;
              MAXDWG = foundrows5.Count() + 1;
              dsSchema.Tables["DRAWINGS"].Rows.Add(drawingnum + "-" + dsMPRS.Tables[0].Rows[0][3].ToString(), dsMPRS.Tables[0].Rows[0][3].ToString(), "", "", MAXDWG, MAXNHA);
              dssch.Tables["DRAWINGS"].Rows.Add(drawingnum + "-" + dsMPRS.Tables[0].Rows[0][3].ToString(), dsMPRS.Tables[0].Rows[0][3].ToString(), "", "", MAXDWG, MAXNHA);
              foundrows5 = dsSchema.Tables["DRAWINGS"].Select(("DWG_NUM = '" + drawingnum + "-" + dsMPRS.Tables[0].Rows[0][3].ToString() + "'"));
            }
            drt = foundrows5[0];



            nhan = Conversions.ToInteger(drt["DRAWINGS_Id"]);

            foundrows5 = dsSchema.Tables["PARTS"].Select(("PART_NUM = '" + HARNESSSYNTH + "'"));
            if (foundrows5.Count() == 0) {
              dsSchema.Tables["PARTS"].Rows.Add(HARNESSSYNTH, "LOOSE WIRE ASSEMBLY", "1", "", "", "ADD", nhan, ku);
              dssch.Tables["PARTS"].Rows.Add(HARNESSSYNTH, "LOOSE WIRE ASSEMBLY", "1", "", "", "ADD", nhan, ku);
              foundrows5 = dsSchema.Tables["PARTS"].Select(("PART_NUM = '" + HARNESSSYNTH + "'"));
              ku = Conversions.ToInteger(foundrows5[0]["LWA_ID"]);
            } else {
              ku = Conversions.ToInteger(foundrows5[0]["LWA_ID"]);
            }













            // GET ADDITIONAL PARTS AND WIRES FROM HARNESS
            DataSet WIREDS = new DataSet();
            WIREDS = data.getData(string.Concat(new string[] {
              "SELECT DISTINCT (bacWireNo),bacLength,WIRE_SPEC_GAGE,bacPlId,WIRE_CABLE_CD FROM TBLCONT,PTP WHERE   bacPlId ='",
              sapPlid,
              "' AND ((bacAction ='ADD')or(bacaction ='REMOVE')) and bacWireno = WIRE_NUMBER and PART_NUMBER ='",
              harnessname,
              "'"
            }));
            source = WIREDS.Tables[0].Select("bacLength ='9992'");
            int num14 = (source.Count() - 1);
            int i = 0;
            while ((i <= num14)) {
              ROW = source[i];
              ROW[1] = "";
              ROW[2] = "";
              i += 1;
            }
            source = WIREDS.Tables[0].Select("bacLength ='WIRE MARKER' and bacWireNo like '%SH%'");
            int num15 = (source.Count() - 1);
            int j = 0;
            while ((j <= num15)) {
              ROW = source[j];
              ROW[2] = "";
              j += 1;
            }
            DataSet set6 = new DataSet();
            source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE <>''");
            int num16 = (source.Count() - 1);
            int k = 0;
            while ((k <= num16)) {
              ROW = source[k];
              set6 = data.getData(("SELECT * FROM PDFWIRE1 WHERE wspecOld ='" + Conversions.ToString(ROW[2]) + "'"));
              if ((set6.Tables[0].Rows.Count != 0)) {
                string str2 = Conversions.ToString(set6.Tables[0].Rows[0][1]);
                ROW[2] = str2;
              }
              k += 1;
            }
            source = WIREDS.Tables[0].Select("bacLength ='WIRE MARKER'");
            int num17 = (source.Count() - 1);
            int m = 0;
            while ((m <= num17)) {
              ROW = source[m];
              ROW[2] = "";
              m += 1;
            }
            source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-20'");
            int num18 = (source.Count() - 1);
            int n = 0;
            while ((n <= num18)) {
              ROW = source[n];
              ROW[2] = "M22759/91-20-9";
              n += 1;
            }
            source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-22'");
            int num19 = (source.Count() - 1);
            int num7 = 0;
            while ((num7 <= num19)) {
              ROW = source[num7];
              ROW[2] = "M22759/91-22-9";
              num7 += 1;
            }
            source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-24'");
            int num20 = (source.Count() - 1);
            int num8 = 0;
            while ((num8 <= num20)) {
              ROW = source[num8];
              ROW[2] = "M22759/81-24-9";
              num8 += 1;
            }
            source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-26'");
            int num21 = (source.Count() - 1);
            int num9 = 0;
            while ((num9 <= num21)) {
              ROW = source[num9];
              ROW[2] = "C20805-26";
              num9 += 1;
            }
            source = WIREDS.Tables[0].Select("bacLength ='9998'");
            int num211 = (source.Count() - 1);
            int num91 = 0;
            while ((num91 <= num211)) {
              ROW = source[num91];
              ROW[1] = "WIRE MARKER";
              num91 += 1;
            }
            source = WIREDS.Tables[0].Select("bacWIRENO LIKE '%WHT%'");
            int num2111 = (source.Count() - 1);
            int num911 = 0;
            while ((num911 <= num2111)) {
              ROW = source[num911];
              WIREDS.Tables[0].Rows.Remove(ROW);
              num911 += 1;
            }
            source = WIREDS.Tables[0].Select("bacWIRENO LIKE '%BLK%'");
            int num22111 = (source.Count() - 1);
            int num9211 = 0;
            while ((num9211 <= num22111)) {
              ROW = source[num9211];
              WIREDS.Tables[0].Rows.Remove(ROW);
              num9211 += 1;
            }
            DataRow[] sourceA = WIREDS.Tables[0].Select("bacLength ='REF'");
            int num14A = (sourceA.Count() - 1);
            int iA = 0;
            while ((iA <= num14A)) {
              ROW = sourceA[iA];
              ROW[1] = "";
              ROW[2] = "";
              iA += 1;
            }
            //ADD WIRES TO SAP


            source = WIREDS.Tables[0].Select("bacWIRENO LIKE '%%'");
            int num222111 = (source.Count() - 1);
            int num92211 = 0;
            while ((num92211 <= num222111)) {
              ROW = source[num92211];

              string wirestr = "";
              if (ROW[1].ToString().Contains("MARKER")) {
                ROW[0] = ROW[0] + " (REF)";
                ROW[2] = "WIRE MARKER";
              }
              try {
                aset.Tables[0].Columns.Add("LENGTH");

              } catch (Exception ex) {

              }
              if (ROW[2] == "") {
                wirestr = "";
              } else if (ROW[2].ToString().Contains("MARKER")) {
                wirestr = ROW[2].ToString();
              } else {

                wirestr = "WIRE (" + ROW[2] + ")";
              }


              dsSchema.Tables["LWA_WIRES"].Rows.Add(ROW[0], ROW[2], ROW[1], "", "ADD", ku);
              if (ROW[1] == "") {
                ROW[1] = 9992;
              } else if (ROW[1] == "WIRE MARKER") {
                ROW[1] = 9992;
              }
              dssch.Tables["LWA_WIRES"].Rows.Add(ROW[0], ROW[2], ROW[1], "", "ADD", ku);


              num92211 += 1;
            }

            DataSet PARTSDS = new DataSet();
            PARTSDS = data.getData(("SELECT * FROM TBLREFDESCOMP WHERE REFCOMPPLID ='" + sapPlid + "' AND REFACTION ='ADD'"));
            int num22 = (aset.Tables[0].Rows.Count - 1);
            // ADD PARTS TO SAP
            source = PARTSDS.Tables[0].Select("PARTNUMBER LIKE '%%'");
            int numP = (source.Count() - 1);
            int numX = 0;
            try {
              aset.Tables[0].Columns.Add("LOCATION");

            } catch (Exception ex) {

            }

            while ((numX <= numP)) {
              ROW = source[numX];
              if (ROW[2] == "REF") {
                ROW[2] = 9992;
              }
              dsSchema.Tables["LWA_PARTS"].Rows.Add(ROW[0], ROW[1], ROW[2], ROW[4], ROW[3], ku);
              dssch.Tables["LWA_PARTS"].Rows.Add(ROW[0], ROW[1], ROW[2], ROW[4], ROW[3], ku);
              //dsSap.Tables(1).Rows.Add(sapPlid, HARNESSSYNTH, ROW.Item(2), ROW.Item(0), ROW.Item(1), drawingnum, "-", "ADD", "", "", 0, 0, "", "", "", ROW.Item(4), drawingnum & "-" & dsMPRS.Tables(0).Rows(0).Item(3).ToString, ku)
              //aset.Tables(0).Rows.Add(sapPlid, HARNESSSYNTH, ROW.Item(2), ROW.Item(0), ROW.Item(1), drawingnum, "-", "ADD")
              numX += 1;
            }


            //

          }

        }

      }

      ///''

      ///''

      aset.AcceptChanges();
      //FOUNDROWS4 = aset.Tables(0).[Select]("PRTECP <>''", "prtecp asc")
      //Dim dtUnique As DataTable
      //Dim DID As Integer
      //DID = 9999

      //' PLCSDataSet.ReadXmlSchema(Application.StartupPath & "/xmlschema1.xsd")
      //Dim dssch As New DataSet
      //dssch.ReadXmlSchema(Application.StartupPath & "/xmlschema2.xsd")
      //Try
      //    dssch.Tables(0).Rows.Add(ECP, 0, KCLTV, KCLFROM, KCLENDS)


      //Catch ex As Exception

      //End Try
      //dtUnique = aset.Tables(0).DefaultView.ToTable(True, "prtEcp")
      //For k = 0 To dtUnique.Rows.Count - 1
      //    Dim NHA As String = ""

      //    ROW = dtUnique(k)
      //    NHA = ROW.Item(0)

      //    dssch.Tables("NHA").Rows.Add(NHA, "B/P", 0, k)
      //    FOUNDROWS4 = aset.Tables(0).[Select]("PRTECP ='" & NHA & "'", "prtdash asc")

      //    Dim row2 As DataRow
      //    Dim dwgnum As String = ""
      //    Dim dwgnum2 As String = ""
      //    For l = 0 To FOUNDROWS4.Count - 1
      //        row2 = FOUNDROWS4(l)
      //        dwgnum = row2.Item(1)
      //        If dwgnum = dwgnum2 Then


      //        Else

      //            If DID = 9999 Then
      //                DID = 0
      //            Else
      //                DID += 1
      //            End If
      //            dssch.Tables("DRAWINGS").Rows.Add(dwgnum, "''", "''", "B/P", DID, k)

      //        End If



      //        Dim LOCAT As String = ""
      //        LOCAT = row2.Item(15).ToString

      //        If LOCAT = "" Then

      //            row2.Item(15) = "-"

      //        End If
      //        If row2.Item(2).ToString.Contains("AR") Then
      //            row2.Item(2) = "9998"

      //        End If

      //        If dwgnum.Contains("H16DW") Then
      //            Try
      //                If row2.Item(4).ToString.Contains("WIRE") Then

      //                    Try
      //                        dssch.Tables("WIRES").Rows.Add(row2.Item(3), row2.Item(4), row2.Item(14), "", row2.Item(7), DID)
      //                    Catch ex As Exception

      //                    End Try

      //                ElseIf row2.Item(3).ToString.StartsWith("W") Then
      //                    Try
      //                        dssch.Tables("WIRES").Rows.Add(row2.Item(3), row2.Item(4), row2.Item(14), "", row2.Item(7), DID)
      //                    Catch ex As Exception

      //                    End Try
      //                Else

      //                    If row2.Item(8) Is DBNull.Value Then
      //                        row2.Item(8) = "-"
      //                    End If
      //                    Dim qtysc As String = ""

      //                    qtysc = row2.Item(4).ToString

      //                    qtysc = qtysc.Substring(qtysc.IndexOf("("))
      //                    qtysc = qtysc.Replace("(", "")
      //                    qtysc = qtysc.Replace(")", "")


      //                    dssch.Tables("PARTS").Rows.Add(row2.Item(3), row2.Item(4), qtysc, row2.Item(15), row2.Item(8), row2.Item(7), DID, k)
      //                End If


      //            Catch ex As Exception

      //            End Try

      //        Else


      //            dssch.Tables("PARTS").Rows.Add(row2.Item(3), row2.Item(4), row2.Item(2), row2.Item(15), row2.Item(8), row2.Item(7), DID, k)
      //        End If






      //        dwgnum2 = dwgnum

      //    Next



      //Next

      //Try
      //    dssch.WriteXml("C:/PLCTP-11.XML")
      //Catch ex As Exception

      //End Try

      //aset.Tables.Item(0).Columns.Add("NOMENCLATURE")
      //aset.Tables.Item(0).Columns.Add("QTY")
      //aset.Tables(0).Columns.Add("COUNTTYPE")
      //aset.Tables.Item(0).Columns.Add("RELDATE")
      //For kl = 0 To aset.Tables(0).Rows.Count - 1
      //    Dim partns As String

      //    frmMain.spr1.Maximum = aset.Tables(0).Rows.Count - 1
      //    frmMain.spr1.Value = kl
      //    frmMain.spr1.ProgressBar.Refresh()
      //    pr1.Properties.Maximum = aset.Tables(0).Rows.Count - 1
      //    pr1.EditValue = kl
      //    pr1.Refresh()
      //    QTYP = 0
      //    partns = aset.Tables(0).Rows(kl).Item("prtPartNumberDoc")
      //    aset2 = data.getData(String.Concat(New String() {"select  prtPartNumberDoc,prtDescription,prtQty,prtInit,prtKCL from tblAssembly where prtKCL like '%?" & KCLTV & KCLENDS.ToString & "%' AND  prtaction ='ADD'  and prtPartNumberDoc='" & partns & "'  and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 ))and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))
      //    Dim NOMEN As String = Nothing
      //    Dim INITF As String = Nothing
      //    Dim NOMEN2 As String = ""
      //    Dim INQTY As Integer = 0

      //    For KL2 = 0 To aset2.Tables(0).Rows.Count - 1
      //        If aset2.Tables(0).Rows(KL2).Item("prtInit") Is DBNull.Value Then
      //            INITF = "C"

      //        Else
      //            INITF = aset2.Tables(0).Rows(KL2).Item("prtInit")
      //        End If
      //        KCLK = aset2.Tables(0).Rows(KL2).Item("prtKcl")


      //        KCKLA = KCLK
      //        NOMEN = aset2.Tables(0).Rows(KL2).Item("prtDescription")
      //        If NOMEN = "COAX" Then
      //            NOMEN = "CABLE ASSEMBLY"
      //        ElseIf NOMEN = "HARNESS" Then
      //            NOMEN = "WIRING HARNESS ASSEMBLY"
      //        End If
      //        QTYSTR = aset2.Tables(0).Rows(KL2).Item("prtQty")
      //        If QTYSTR.Contains("IN") Then
      //            QTYSTR = QTYSTR.Substring(0, QTYSTR.IndexOf("IN")).Trim
      //            QTYP = QTYP + Int(QTYSTR)
      //            QTYYPSTR = QTYP.ToString & " IN"
      //        ElseIf QTYSTR.Contains("REF") Then
      //            QTYYPSTR = QTYSTR
      //        ElseIf QTYSTR.Contains("A") Then
      //            QTYYPSTR = QTYSTR
      //        ElseIf QTYSTR.Contains("a") Then
      //            QTYYPSTR = QTYSTR
      //        ElseIf partns = "P5374-1" Then
      //            If QTYP = 0 Then
      //                NOMEN2 = NOMEN
      //            Else
      //                NOMEN2 = NOMEN2 & ", " & NOMEN.Substring(5)


      //            End If

      //            QTYP = QTYP + Int(QTYSTR)
      //            QTYYPSTR = QTYP.ToString
      //        ElseIf partns = "P5393-1" Then
      //            If QTYP = 0 Then
      //                If NOMEN.Contains("IN") Then
      //                    INQTY = NOMEN.Substring(NOMEN.IndexOf("(") + 1, 2)
      //                End If
      //                QTYP = INQTY
      //                NOMEN2 = NOMEN
      //            Else
      //                If NOMEN.Contains("IN") Then
      //                    INQTY = INQTY + NOMEN.Substring(NOMEN.IndexOf("(") + 1, 2)

      //                End If
      //                NOMEN2 = NOMEN2 & ", " & NOMEN.Substring(5)

      //                QTYYPSTR = INQTY.ToString & " IN"


      //            End If

      //        Else
      //            QTYP = QTYP + Int(QTYSTR)
      //            QTYYPSTR = QTYP.ToString
      //        End If

      //    Next

      //    Try
      //        Dim num5 As Integer
      //        Dim row7 As DataRow
      //        Dim rowArray7 As DataRow()
      //        source = aset.Tables.Item(0).[Select](("prtPartNumberDoc ='" & partns & "'"))

      //        Dim num321 As Integer = (source.Count() - 1)
      //        num5 = 0
      //        Do While (num5 <= num321)
      //            row7 = source(num5)
      //            row7.Item(2) = QTYYPSTR
      //            If partns = "P5374-1" Then
      //                row7.Item(1) = NOMEN2
      //            ElseIf partns = "P5393-1" Then
      //                NOMEN = NOMEN.Substring(0, NOMEN.IndexOf("(")).Trim
      //                row7.Item(1) = NOMEN
      //            Else
      //                row7.Item(1) = NOMEN
      //            End If

      //            row7.Item(3) = INITF
      //            row7.Item(4) = KCLK
      //            num5 += 1
      //        Loop

      //    Catch ex As Exception

      //    End Try

      //Next
      //ASET3 = data.getData(String.Concat(New String() {"select distinct prtPartNumberDoc from tblAssembly where prtKCL not like '%?" & KCLTV & KCLENDS.ToString & "%' AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))
      //'ASET3 = Data.getData(String.Concat(New String() {"select distinct prtPartNumberDoc from tblAssembly where ((prtKCL NOT like '%?" & TypeVer & effEnds.ToString & "%') or (prtKCL is null))  AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))
      //If ASET3.Tables(0).Rows.Count = 0 Then
      //    KCLK = KCLK
      //    KCKLA = KCLK
      //Else
      //    If relasA = False Then
      //        KCLK = ""
      //    Else
      //        If aset.Tables(0).Rows.Count = 0 Then
      //            KCKLA = "456"
      //            KCLK = "?" + KCLTV + KCLENDS.ToString + "^" + DateString + expor + "!"
      //        Else
      //            KCLK = "?" + KCLTV + KCLENDS.ToString + "^" + DateString + expor + "!"
      //            KCKLA = KCLK
      //        End If

      //    End If


      //    Try
      //        aset.Tables.Item(0).Columns.Add("NOMENCLATURE")
      //        aset.Tables.Item(0).Columns.Add("QTY")
      //        aset.Tables(0).Columns.Add("COUNTTYPE")
      //        aset.Tables.Item(0).Columns.Add("RELDATE")

      //    Catch ex As Exception

      //    End Try

      //    For kl = 0 To ASET3.Tables(0).Rows.Count - 1
      //        Dim partns As String
      //        QTYP = 0
      //        frmMain.spr1.Maximum = ASET3.Tables(0).Rows.Count - 1
      //        frmMain.spr1.Value = kl
      //        frmMain.spr1.ProgressBar.Refresh()
      //        pr1.Properties.Maximum = ASET3.Tables(0).Rows.Count - 1
      //        pr1.EditValue = kl
      //        pr1.Refresh()
      //        QTYP = 0

      //        partns = ASET3.Tables(0).Rows(kl).Item("prtPartNumberDoc")
      //        aset2 = data.getData(String.Concat(New String() {"select  prtPartNumberDoc,prtDescription,prtQty,prtInit,prtKCL from tblAssembly WHERE prtaction ='ADD'  and prtPartNumberDoc='" & partns & "'  and ((prtTypeVer ='", KCLTV, "' and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 ))  and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc"}))
      //        Dim NOMEN As String
      //        Dim nomen2 As String = ""
      //        Dim INITF As String
      //        Dim OLDKCL As String
      //        Dim NEWKCL As String
      //        Dim OLDKCL2 As String
      //        Try

      //        Catch ex As Exception

      //        End Try
      //        If aset2.Tables(0).Rows.Count > 3 Then
      //            QTYP = 0
      //        End If
      //        For KL2 = 0 To aset2.Tables(0).Rows.Count - 1

      //            QTYSTR = ""
      //            If aset2.Tables(0).Rows(KL2).Item("prtInit") Is DBNull.Value Then
      //                INITF = "C"

      //            Else
      //                If INITF = "" Then
      //                    INITF = "C"
      //                Else
      //                    INITF = aset2.Tables(0).Rows(KL2).Item("prtInit")
      //                End If

      //            End If
      //            ' KCLK = aset2.Tables(0).Rows(KL2).Item("prtKcl")
      //            NOMEN = aset2.Tables(0).Rows(KL2).Item("prtDescription")
      //            If NOMEN = "COAX" Then
      //                NOMEN = "CABLE ASSEMBLY"
      //            ElseIf NOMEN = "HARNESS" Then
      //                NOMEN = "WIRING HARNESS ASSEMBLY"
      //            End If
      //            QTYSTR = aset2.Tables(0).Rows(KL2).Item("prtQty")
      //            If QTYSTR.Contains("IN") Then
      //                QTYSTR = QTYSTR.Substring(0, QTYSTR.IndexOf("IN")).Trim
      //                QTYP = QTYP + Int(QTYSTR)
      //                QTYYPSTR = QTYP.ToString & " IN"
      //            ElseIf QTYSTR.Contains("REF") Then
      //                QTYYPSTR = QTYSTR
      //            ElseIf QTYSTR.Contains("A") Then
      //                QTYYPSTR = QTYSTR
      //            ElseIf QTYSTR.Contains("a") Then
      //                QTYYPSTR = QTYSTR
      //            ElseIf partns = "P5374-1" Then
      //                If QTYP = 0 Then
      //                    NOMEN2 = NOMEN
      //                Else
      //                    If NOMEN = "TAPE" Then
      //                    Else
      //                        nomen2 = nomen2 & ", " & NOMEN.Substring(5)

      //                    End If


      //                End If

      //                QTYP = QTYP + Int(QTYSTR)
      //                QTYYPSTR = QTYP.ToString
      //            Else
      //                If QTYSTR = "" Then
      //                Else
      //                    QTYP = QTYP + Int(QTYSTR)
      //                    QTYYPSTR = QTYP.ToString
      //                End If
      //            End If


      //        Next
      //        Try
      //            Dim num5 As Integer
      //            Dim row7 As DataRow
      //            Dim rowArray7 As DataRow()
      //            source = aset.Tables.Item(0).[Select](("prtPartNumberDoc ='" & partns & "'"))

      //            Dim num321 As Integer = (source.Count() - 1)
      //            num5 = 0
      //            If num321 = -1 Then
      //                If partns = "P5374-1" Then
      //                    aset.Tables(0).Rows.Add(partns, nomen2, QTYYPSTR, INITF, KCLK)
      //                Else
      //                    aset.Tables(0).Rows.Add(partns, NOMEN, QTYYPSTR, INITF, KCLK)
      //                End If

      //                'For KL2 = 0 To aset2.Tables(0).Rows.Count - 1
      //                '    If relasA = True Then
      //                '        OLDKCL = aset2.Tables(0).Rows(KL2).Item("prtKCL")
      //                '        If OLDKCL.Contains("?" + TypeVer + effEnds.ToString) Then
      //                '            OLDKCL2 = OLDKCL
      //                '            OLDKCL = OLDKCL.Replace(OLDKCL.Substring(OLDKCL.IndexOf("?" + TypeVer + effEnds.ToString + "^"), KCLK.Length), KCLK)
      //                '            NEWKCL = OLDKCL
      //                '        Else
      //                '            OLDKCL2 = OLDKCL
      //                '            NEWKCL = OLDKCL + KCLK
      //                '        End If
      //                '        'Data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='" & NEWKCL & "' WHERE PRTKCL ='" & OLDKCL2 & "' AND PRTPARTNUMBERDOC ='" & partns & "' and ((prtTypeVer ='" & KCLTV & "'and " & KCLENDS & " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='" & KCLTV & "' and (" & KCLENDS & " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%')))")
      //                '    End If
      //                'Next


      //            Else
      //                Do While (num5 <= num321)
      //                    row7 = source(num5)
      //                    row7.Item(2) = QTYYPSTR
      //                    If partns = "P5374-1" Then
      //                        row7.Item(1) = nomen2
      //                    Else
      //                        row7.Item(1) = NOMEN
      //                    End If
      //                    row7.Item(4) = KCLK
      //                    row7.Item(3) = INITF
      //                    num5 += 1
      //                Loop
      //            End If

      //            'If relasA = True Then
      //            '    data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='" & DateString & "' WHERE PRTPARTNUMBERDOC ='" & partns & "' and ((prtTypeVer ='" & KCLTV & "'and " & KCLENDS & " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='" & KCLTV & "' and (" & KCLENDS & " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%')))")
      //            'End If




      //        Catch ex As Exception

      //        End Try

      //    Next


      //End If
      //Dim aset4 As New DataSet
      //aset4 = data.getData(String.Concat(New String() {"SELECT * FROM TBLGENERAL WHERE ((genPlannumber LIKE '30%') OR (genPlannumber LIKE '50%')) AND GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' )) order by  genPlannumber"}))
      //If ASET3.Tables(0).Rows.Count = 0 Then
      //    If aset.Tables(0).Rows.Count = 0 Then
      //        KCKLA = "456"
      //        KCLK = "?" + KCLTV + KCLENDS.ToString + "^" + DateString + expor + "!"
      //    Else
      //        KCLK = "?" + KCLTV + KCLENDS.ToString + "^" + DateString + expor + "!"
      //        KCKLA = KCLK
      //    End If
      //Else

      //End If





      //For kl3 = 0 To aset4.Tables(0).Rows.Count - 1
      //    Dim harnesnumb As String = Nothing
      //    Dim tbd As String = Nothing
      //    Dim kld As String = Nothing
      //    Dim CKLS As String = Nothing
      //    harnesnumb = aset4.Tables(0).Rows(kl3).Item("genPartsNote")
      //    If harnesnumb.Contains("OBTAIN WIRES FROM LWA : ______") Then
      //    Else
      //        tbd = harnesnumb.Substring(23, harnesnumb.IndexOf(". ") - 23).Trim
      //        If tbd.Length <= 9 Then
      //            tbd = tbd + "-TBD"
      //        End If
      //        kld = aset4.Tables(0).Rows(kl3).Item("genPdf2")
      //        If kld = "-" Then
      //            CKLS = KCLK
      //        Else
      //            CKLS = kld
      //        End If
      //        Try
      //            aset.Tables(0).Rows.Add(tbd, "LOOSE WIRE ASSEMBLY", "1", "C", CKLS)
      //        Catch ex As Exception

      //        End Try
      //    End If


      //Next
      //Dim XR As New xrKCL

      //Qseg = aset.Tables(0).Rows.Count




      //For T = 0 To aset.Tables(0).Rows.Count - 1
      //    Try
      //        QR = aset.Tables(0).Rows(T).Item("QTY")
      //        QN = QN + QR

      //    Catch ex As Exception
      //        QN = QN + 1

      //    End Try
      //Next
      try {

      } catch (Exception ex) {

      }
      ///'' GridControl1.DataSource = aset.Tables(0)
      //Dim data As New clsData
      //Dim aset As New DataSet
      //Dim aset2 As New DataSet
      //Dim ASET3 As New DataSet
      //Dim dataSet As New DataSet
      //Dim set2 As New DataSet
      //Dim set3 As New DataSet
      //Dim search As New frmSearch
      //Dim QTYP As Integer
      //Dim QTYYPSTR As String
      //Dim QTYSTR As String
      //Dim source As DataRow()
      //Dim expor As String
      //Dim KCLK As String
      //expor = Guid.NewGuid.ToString
      //Dim relasA As Boolean = False
      //Dim ans As DialogResult
      //RELAS = False

      //ans = XtraMessageBox.Show("          KIT CONTENT LIST" & vbCrLf & "       (ONLY FOR REFERENCE)" & vbCrLf & "    For authorized release please" & vbCrLf & "            click publish button" & vbCrLf & vbCrLf & "               CONTINUE ?", "KCL", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3)
      //If ans = Windows.Forms.DialogResult.Yes Then
      //    RELAS = True
      //Else
      //    Exit Sub
      //End If
      //'KCLTV = (Me.viewKCL.GetRowCellValue(Me.viewKCL.GetSelectedRows(0), "tlTypeVer"))
      //'KCLENDS = (Me.viewKCL.GetRowCellValue(Me.viewKCL.GetSelectedRows(0), "tlNumber"))
      //'Module1.TailNo = (Me.viewKCL.GetRowCellValue(Me.viewKCL.GetSelectedRows(0), "tlSerial"))
      //aset = data.getData(String.Concat(New String() {"select distinct prtPartNumberDoc from tblAssembly where ( (PRTKCL <>'-') OR (prtKCL like '%?" & TypeVer & effEnds.ToString & "%')) AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))
      //aset.Tables.Item(0).Columns.Add("NOMENCLATURE")
      //aset.Tables.Item(0).Columns.Add("QTY")
      //aset.Tables(0).Columns.Add("COUNTTYPE")
      //aset.Tables.Item(0).Columns.Add("RELDATE")
      //For kl = 0 To aset.Tables(0).Rows.Count - 1
      //    Dim partns As String

      //    frmMain.spr1.Maximum = aset.Tables(0).Rows.Count - 1
      //    frmMain.spr1.Value = kl
      //    frmMain.spr1.ProgressBar.Refresh()
      //    pr1.Properties.Maximum = aset.Tables(0).Rows.Count - 1
      //    pr1.EditValue = kl
      //    pr1.Refresh()
      //    QTYP = 0
      //    partns = aset.Tables(0).Rows(kl).Item("prtPartNumberDoc")
      //    aset2 = data.getData(String.Concat(New String() {"select  prtPartNumberDoc,prtDescription,prtQty,prtInit,prtKCL from tblAssembly where ((PRTKCL <>'-') AND (prtKCL like '%?" & TypeVer & effEnds.ToString & "%')) AND  prtaction ='ADD'  and prtPartNumberDoc='" & partns & "'  and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) order by prtPartNumberDoc "}))
      //    Dim NOMEN As String
      //    Dim INITF As String

      //    For KL2 = 0 To aset2.Tables(0).Rows.Count - 1
      //        If aset2.Tables(0).Rows(KL2).Item("prtInit") Is DBNull.Value Then
      //            INITF = "C"

      //        Else
      //            INITF = aset2.Tables(0).Rows(KL2).Item("prtInit")
      //        End If
      //        KCLK = aset2.Tables(0).Rows(KL2).Item("prtKcl")

      //        KCKLA = KCLK
      //        NOMEN = aset2.Tables(0).Rows(KL2).Item("prtDescription")
      //        QTYSTR = aset2.Tables(0).Rows(KL2).Item("prtQty")
      //        If QTYSTR.Contains("IN") Then
      //            QTYSTR = QTYSTR.Substring(0, QTYSTR.IndexOf("IN")).Trim
      //            QTYP = QTYP + Int(QTYSTR)
      //            QTYYPSTR = QTYP.ToString & " IN"
      //        ElseIf QTYSTR.Contains("REF") Then
      //            QTYYPSTR = QTYSTR
      //        ElseIf QTYSTR.Contains("A") Then
      //            QTYYPSTR = QTYSTR
      //        Else
      //            QTYP = QTYP + Int(QTYSTR)
      //            QTYYPSTR = QTYP.ToString
      //        End If

      //    Next
      //    Try
      //        Dim num5 As Integer
      //        Dim row7 As DataRow
      //        Dim rowArray7 As DataRow()
      //        source = aset.Tables.Item(0).[Select](("prtPartNumberDoc ='" & partns & "'"))

      //        Dim num321 As Integer = (source.Count() - 1)
      //        num5 = 0
      //        Do While (num5 <= num321)
      //            row7 = source(num5)
      //            row7.Item(2) = QTYYPSTR
      //            row7.Item(1) = NOMEN
      //            row7.Item(3) = INITF
      //            row7.Item(4) = KCLK
      //            num5 += 1
      //        Loop

      //    Catch ex As Exception

      //    End Try

      //Next

      //ASET3 = data.getData(String.Concat(New String() {"select distinct prtPartNumberDoc from tblAssembly where ((PRTKCL ='-') OR  (prtKCL not like '%?" & TypeVer & effEnds.ToString & "%')) AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))
      //'ASET3 = data.getData(String.Concat(New String() {"select distinct prtPartNumberDoc from tblAssembly where ((PRTKCL ='') or (PRTKCL IS  NULL)) AND prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))

      //If ASET3.Tables(0).Rows.Count = 0 Then
      //    KCLK = KCLK
      //    KCKLA = KCLK
      //Else
      //    If relasA = False Then
      //        KCLK = ""
      //    Else
      //        KCLK = "?" + TypeVer + effEnds + DateString + expor + "!"
      //    End If
      //    If aset.Tables(0).Rows.Count = 0 Then
      //        KCKLA = "456"
      //    Else
      //        KCKLA = KCLK
      //    End If

      //    Try
      //        aset.Tables.Item(0).Columns.Add("NOMENCLATURE")
      //        aset.Tables.Item(0).Columns.Add("QTY")
      //        aset.Tables(0).Columns.Add("COUNTTYPE")
      //        aset.Tables.Item(0).Columns.Add("RELDATE")

      //    Catch ex As Exception

      //    End Try

      //    For kl = 0 To ASET3.Tables(0).Rows.Count - 1
      //        Dim partns As String

      //        frmMain.spr1.Maximum = ASET3.Tables(0).Rows.Count - 1
      //        frmMain.spr1.Value = kl
      //        frmMain.spr1.ProgressBar.Refresh()
      //        pr1.Properties.Maximum = ASET3.Tables(0).Rows.Count - 1
      //        pr1.EditValue = kl
      //        pr1.Refresh()
      //        QTYP = 0

      //        partns = ASET3.Tables(0).Rows(kl).Item("prtPartNumberDoc")
      //        aset2 = data.getData(String.Concat(New String() {"select  prtPartNumberDoc,prtDescription,prtQty,prtInit,prtKCL from tblAssembly WHERE prtaction ='ADD'  and prtPartNumberDoc='" & partns & "'  and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) order by prtPartNumberDoc "}))
      //        Dim NOMEN As String
      //        Dim INITF As String

      //        For KL2 = 0 To aset2.Tables(0).Rows.Count - 1
      //            If aset2.Tables(0).Rows(KL2).Item("prtInit") Is DBNull.Value Then
      //                INITF = "C"

      //            Else
      //                INITF = aset2.Tables(0).Rows(KL2).Item("prtInit")
      //            End If
      //            ' KCLK = aset2.Tables(0).Rows(KL2).Item("prtKcl")
      //            NOMEN = aset2.Tables(0).Rows(KL2).Item("prtDescription")
      //            QTYSTR = aset2.Tables(0).Rows(KL2).Item("prtQty")
      //            If QTYSTR.Contains("IN") Then
      //                QTYSTR = QTYSTR.Substring(0, QTYSTR.IndexOf("IN")).Trim
      //                QTYP = QTYP + Int(QTYSTR)
      //                QTYYPSTR = QTYP.ToString & " IN"
      //            ElseIf QTYSTR.Contains("REF") Then
      //                QTYYPSTR = QTYSTR
      //            ElseIf QTYSTR.Contains("A") Then
      //                QTYYPSTR = QTYSTR
      //            Else
      //                QTYP = QTYP + Int(QTYSTR)
      //                QTYYPSTR = QTYP.ToString
      //            End If
      //        Next
      //        Try
      //            Dim num5 As Integer
      //            Dim row7 As DataRow
      //            Dim rowArray7 As DataRow()
      //            source = aset.Tables.Item(0).[Select](("prtPartNumberDoc ='" & partns & "'"))

      //            Dim num321 As Integer = (source.Count() - 1)
      //            num5 = 0
      //            If num321 = -1 Then
      //                aset.Tables(0).Rows.Add(partns, NOMEN, QTYP, INITF, KCLK)
      //                If relasA = True Then
      //                    data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='" & KCLK & "' WHERE PRTPARTNUMBERDOC ='" & partns & "' and ((prtTypeVer ='" & KCLTV & "'and " & KCLENDS & " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='" & KCLTV & "' and (" & KCLENDS & " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%')))")
      //                End If

      //            Else
      //                Do While (num5 <= num321)
      //                    row7 = source(num5)
      //                    row7.Item(2) = QTYYPSTR
      //                    row7.Item(1) = NOMEN
      //                    row7.Item(4) = KCLK
      //                    row7.Item(3) = INITF
      //                    num5 += 1
      //                Loop
      //            End If

      //            If relasA = True Then
      //                data.ExecuteSQL("UPDATE TBLASSEMBLY SET PRTKCL ='" & DateString & "' WHERE PRTPARTNUMBERDOC ='" & partns & "' and ((prtTypeVer ='" & KCLTV & "'and " & KCLENDS & " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS PRTPLID FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPlid from tblEffectivities where (efTypeVer ='" & KCLTV & "' and (" & KCLENDS & " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%')))")
      //            End If

      //            num5 += 1


      //        Catch ex As Exception

      //        End Try

      //    Next


      //End If


      //Dim XR As New xrKCL
      //GridControl1.DataSource = aset.Tables(0)
      //GridControl1.RefreshDataSource()
      //relas = False
      //XR.grdKCL.DataSource = aset.Tables(0)
      //XR.txtDate.Text = DateString
      //XR.RELDA = KCLK
      //XR.ShowPreview()
      SimpleButton5.Enabled = true;
      dssch2 = dssch.Copy();

      MessageBox.Show("CALCULATION DONE", "MKPL", MessageBoxButtons.OK);

    }

    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton4_Click(System.Object sender, System.EventArgs e)
    {
      clsData data = new clsData();
      DataRow ROW;
      DataSet aset = new DataSet();
      DataSet aset2 = new DataSet();
      DataSet ASET3 = new DataSet();
      DataSet dataSet = new DataSet();
      DataSet set2 = new DataSet();
      DataSet set3 = new DataSet();
      frmSearch search = new frmSearch();
      int QTYP = 0;
      string QTYSTR = null;
      DataRow[] source;
      string expor;
      string KCLK = null;
      Module1.newModule.QN = 0;
      Module1.newModule.QR = 0;
      Module1.newModule.Qseg = "";
      ListBoxControl1.Items.Clear();
      m_Success = false;
      if (cmbTail.Text == "") {
        XtraMessageBox.Show("Please select a T/V", "MKPL");
        return;
      }
      if (ComboBoxEdit1.Text == "") {
        XtraMessageBox.Show("Please select FROM", "MKPL");
        return;
      }
      if (ComboBoxEdit2.Text == "") {
        XtraMessageBox.Show("Please select TO", "MKPL");
        return;
      }
      Module1.newModule.KCLENDS = Conversions.ToInteger(ComboBoxEdit2.Text);//JMR -- look at -- converted it to integer. But should it be converted ot integer or should the variable be changed to a string?
      KCLFROM = Conversions.ToInteger(ComboBoxEdit1.Text);
      string QTYYPSTR = null;
      expor = Guid.NewGuid().ToString();
      bool relasA = false;
      DialogResult ans;
      Module1.newModule.RELAS = false;
      ans = XtraMessageBox.Show("  Export data to xml?", "SAP EXPORT", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
      if (ans == DialogResult.Yes) {


      } else {
        return;
      }
      DataSet dsf = new DataSet();
      DataSet dsf2 = new DataSet();
      string revDate = "";
      DataSet SSD = new DataSet();
      string REVNOTE = "";
      dsf.ReadXmlSchema((System.Windows.Forms.Application.StartupPath + "\\tes1.xml"));
      dsf2.ReadXml((System.Windows.Forms.Application.StartupPath + "\\tes1.xml"));

      DataRow[] FOUNDROWS2;//JMR -- took Data. off Data.DataRow[]
      DataRow drt = null;//JMR -- DEV -- nulled it
      DataRow[] foundrows3;//JMR -- took Data. off Data.DataRow[]
      DataRow drt3;
      string harnessrow = "";
      int tc = 0;
      // Exit Sub

      aset = data.getData(string.Concat(new string[] {
        "select * from  tblAssembly where prtpartNumberDoc <>'' and prtaction <>'REINSTALL' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='",
        Module1.newModule.KCLTV,
        "'and ",
        Module1.newModule.KCLENDS.ToString(),
        " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Module1.newModule.KCLENDS.ToString(),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "
      }));

      int DID = 0;
      int plcid = 0;
      int PRTID = 0;

      dsf.Tables[0].Rows.Add("2818", 0);

      dsf.Tables["TVES"].Rows.Add(Module1.newModule.KCLTV, KCLFROM, Module1.newModule.KCLENDS, System.DBNull.Value, System.DBNull.Value, System.DBNull.Value, plcid);



      for (int KLP = 0; KLP <= aset.Tables[0].Rows.Count - 1; KLP++) {
        pr1.Properties.Maximum = aset.Tables[0].Rows.Count - 1;
        pr1.EditValue = KLP;
        pr1.Refresh();
        revDate = null;
        REVNOTE = null;
        this.PLANNUMBER = aset.Tables[0].Rows[KLP]["prtPlId"].ToString();
        DataSet gends = new DataSet();
        gends = data.getData("select * from tblGeneral where genplid ='" + this.PLANNUMBER + "'");
        string rev = "";
        try {
          rev = gends.Tables[0].Rows[0]["genRevHng"].ToString();

        } catch (Exception ex) {
          rev = "";

        }

        if (rev != "") {
          SSD = data.getData("select WIRENO,PIN FROM PDFWIRES WHERE TERM ='" + this.PLANNUMBER + "' AND REFDES ='" + rev + "'");
          //revDate = SSD.Tables(0).Rows(0).Item(0)
          //REVNOTE = SSD.Tables(0).Rows(0).Item(1)
        }

        try {
          FOUNDROWS2 = dsf.Tables["plcDataset"].Select(("PLC_NO='" + gends.Tables[0].Rows[0]["genPlannumber"] + "'"));
          if (FOUNDROWS2.Count() == 0) {
              dsf.Tables["plcDataset"].Rows.Add(gends.Tables[0].Rows[0]["genPlannumber"].ToString().Trim(), rev, gends.Tables[0].Rows[0]["genDescription"], frmMain.start.cmbProgram.Text, gends.Tables[0].Rows[0]["genTeam"], gends.Tables[0].Rows[0]["genAcArea"], revDate, REVNOTE, Module1.newModule.ECP);

            FOUNDROWS2 = dsf.Tables["plcDataset"].Select(("PLC_NO='" + gends.Tables[0].Rows[0]["genPlannumber"] + "'"));


            drt = FOUNDROWS2[0];
            drt[10] = 0;
            dsf.AcceptChanges();

            plcid = Conversions.ToInteger(drt[9]);
          } else {
            drt = FOUNDROWS2[0];

            plcid = Conversions.ToInteger(drt[9]);
          }
        } catch (Exception ex) {

        }
        try {
          FOUNDROWS2 = dsf.Tables["TVES"].Select(("PLCDATASET_ID =" + plcid + ""));
          if (FOUNDROWS2.Count() == 0) {
              dsf.Tables["TVES"].Rows.Add(Module1.newModule.KCLTV, KCLFROM, Module1.newModule.KCLENDS, System.DBNull.Value, System.DBNull.Value, plcid);

          } else {

          }
        } catch (Exception ex) {

        }

        try {
          DataSet asetdwg = new DataSet();
          asetdwg = new clsData().getData(string.Concat(new string[] {
            "SELECT DISTINCT dwgPartnumber,dwgDescription,dwgNotes,dwgTypever,dwgFrom,dwgThru FROM TBLDRAWINGS WHERE DWGPLID = '",
            this.PLANNUMBER,
            "' and ((dwgTypeVer ='",
            Module1.newModule.KCLTV,
            "' and ",
            Module1.newModule.KCLENDS.ToString(),
            " between dwgfrom and dwgThru ) or ( dwgTypeVer = '999' and dwgThru = 9999) or ( dwgTypeVer = '0' and dwgThru = 0) OR (dwgTypeVer ='999' and ",
            Module1.newModule.KCLENDS.ToString(),
            " between dwgfrom and dwgThru ))"
          }));

          for (int dwg = 0; dwg <= asetdwg.Tables[0].Rows.Count - 1; dwg++) {
            //    dsf.Tables("DRAWINGS").Rows.Add(NewHarnessPTP.Substring(0, NewHarnessPTP.IndexOf("-").ToString.Trim), OldHarnessPTP.Substring(OldHarnessPTP.IndexOf("-") + 1.ToString.Trim), NewHarnessPTP.Substring(NewHarnessPTP.IndexOf("-").ToString.Trim + 1), "HARNESS", PID, plcid)
            object objValue;
            FOUNDROWS2 = dsf.Tables["DRAWINGS"].Select("PLCDATASET_ID ='" + plcid + "' AND dwg_num ='" + asetdwg.Tables[0].Rows[dwg][0] + "'");

            if (FOUNDROWS2.Count() == 0) {
              objValue = dsf.Tables["DRAWINGS"].Compute("MAX (DRAWINGS_Id)", "");
              if (object.ReferenceEquals(objValue, DBNull.Value)) {
                DID = 0;
              } else {
                DID = Conversions.ToInteger(objValue) + 1;//JMR -- changed Int to Conversions.ToInteger

              }
              dsf.Tables["DRAWINGS"].Rows.Add(asetdwg.Tables[0].Rows[dwg][0], "", "", asetdwg.Tables[0].Rows[dwg][1], DID, plcid);
            } else {

            }


          }



        } catch (Exception ex) {

        }


        try {


          // FOUNDROWS2 = 
          object objValue;


          objValue = dsf.Tables["PARTS"].Compute("MAX (PARTS_Id)", "");
          if (object.ReferenceEquals(objValue, DBNull.Value)) {
            PRTID = 0;
          } else {
            PRTID = Conversions.ToInteger(objValue) + 1;//JMR -- Changed Int to Conversions.ToInteger

          }


          //Next


        } catch (Exception ex) {

        }
        drt = aset.Tables[0].Rows[KLP];

        try {
          object objValue;
          FOUNDROWS2 = dsf.Tables["DRAWINGS"].Select("PLCDATASET_ID ='" + plcid + "' AND DWG_NUM='" + drt[5] + "'");


          if (FOUNDROWS2.Count() == 0) {
            objValue = dsf.Tables["DRAWINGS"].Compute("MAX (DRAWINGS_Id)", "");
            if (object.ReferenceEquals(objValue, DBNull.Value)) {
              DID = 0;
            } else {
                DID = Conversions.ToInteger(objValue);//JMR -- Changed Int to Conversions.ToInteger

            }

          } else {
            FOUNDROWS2 = dsf.Tables["DRAWINGS"].Select("PLCDATASET_ID ='" + plcid + "'AND DWG_NUM='" + drt[5] + "'");

            drt3 = FOUNDROWS2[0];
            DID = Conversions.ToInteger(drt3[4]);
          }
        } catch (Exception ex) {

        }

        string dwgz = "";//JMR -- DEV -- nulled it
        if (drt[8] == "-") {
          dwgz = System.DBNull.Value.ToString();

        }
        string prtloc = null;
        prtloc = System.DBNull.Value.ToString();
        if (drt[3].ToString().StartsWith("P5374")) {
        } else if (drt[3].ToString().StartsWith("P5373")) {
        } else if (drt[3].ToString().StartsWith("P5269")) {


        } else {
          dsf.Tables["parts"].Rows.Add(drt[3], drt[4], drt[2], prtloc, dwgz, drt[7], PRTID, DID);

        }



        //         dsf.WriteXml(Application.StartupPath & "\NICK.XML")
      }


      //Dim FOUNDROWS4() As Data.DataRow

      //FOUNDROWS4 = aset.Tables(0).[Select](("prtEcp <> ''"))
      //Dim num49 As Integer = (FOUNDROWS4.Count - 1)
      //Dim i4 As Integer = 0
      //Do While (i4 <= num49)
      //    drt = FOUNDROWS4(i4)
      //    drt.Item(1) = drt.Item(5) & "-" & drt.Item(1)
      //    i4 = i4 + 1

      //Loop
      clsData data2 = new clsData();


      DataSet ASSYDS = new DataSet();

      ASSYDS = data.getData(string.Concat(new string[] {
        "SELECT * FROM tblGeneral WHERE ((genplannumber like '30%') or (genplannumber like '50%')) and genPlId in([select] efPlId as genPlId from tblEffectivities where (efTypeVer ='",
        Module1.newModule.KCLTV,
        "' and (",
        Module1.newModule.KCLENDS.ToString(),
        " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' )) ORDER BY GENPLANNUMBER"
      }));
      for (int kl = 0; kl <= ASSYDS.Tables[0].Rows.Count - 1; kl++) {
        pr1.Properties.Maximum = ASSYDS.Tables[0].Rows.Count - 1;
        pr1.EditValue = kl;
        pr1.Refresh();
        string harnessname = "";
        DataSet dsMPRS = new DataSet();
        string drawingnum = "";
        string rev = "";
        this.PLANNUMBER = ASSYDS.Tables[0].Rows[kl]["genplid"].ToString();

        try {
          rev = ASSYDS.Tables[0].Rows[kl]["genRevHng"].ToString();

        } catch (Exception ex) {
          rev = "";

        }

        if (rev != "") {
          SSD = data2.getData("select WIRENO,PIN FROM PDFWIRES WHERE TERM ='" + this.PLANNUMBER + "' AND REFDES ='" + rev + "'");
          //revDate = SSD.Tables(0).Rows(0).Item(0)
          //REVNOTE = SSD.Tables(0).Rows(0).Item(1)
        }

        try {
          FOUNDROWS2 = dsf.Tables[2].Select(("PLC_NO='" + ASSYDS.Tables[0].Rows[kl]["genPlannumber"] + "'"));
          if (FOUNDROWS2.Count() == 0) {

            dsf.Tables[2].Rows.Add(ASSYDS.Tables[0].Rows[kl]["genPlannumber"].ToString().Trim(), rev, ASSYDS.Tables[0].Rows[kl]["genDescription"], frmMain.start.cmbProgram.Text, ASSYDS.Tables[0].Rows[kl]["genTeam"], ASSYDS.Tables[0].Rows[kl]["genAcArea"], revDate, REVNOTE, Module1.newModule.ECP);
            FOUNDROWS2 = dsf.Tables[2].Select(("PLC_NO='" + ASSYDS.Tables[0].Rows[kl]["genPlannumber"] + "'"));
            drt = FOUNDROWS2[0];

            drt[10] = 0;
            dsf.AcceptChanges();
            plcid = Conversions.ToInteger(drt[9]);
          } else {
            drt = FOUNDROWS2[0];

            plcid = Conversions.ToInteger(drt[9]);
          }
        } catch (Exception ex) {

        }


        int PID = 0;
        DataSet dsid = new DataSet();

        DataSet set6 = new DataSet();

        DataSet harnds = new DataSet();
        string sapPlid = "";
        clsData data34 = new clsData();
        harnds = data34.getData("SELECT * FROM TBLSELHARNESS WHERE hrnSelPlId='" + this.PLANNUMBER + "'");
        sapPlid = harnds.Tables[0].Rows[0][0].ToString();
        sapPlid = this.PLANNUMBER;
        harnessname = harnds.Tables[0].Rows[0][2].ToString();
        Module1.newModule.NewHarnessPTP = harnds.Tables[0].Rows[0][2].ToString();
        Module1.newModule.OldHarnessPTP = harnds.Tables[0].Rows[0][1].ToString();

        try {


          // FOUNDROWS2 = 
          object objValue;
          FOUNDROWS2 = dsf.Tables["DRAWINGS"].Select("PLCDATASET_ID ='" + plcid + "' AND DESCRIPTION ='HARNESS'");

          if (FOUNDROWS2.Count() == 0) {
            objValue = dsf.Tables["DRAWINGS"].Compute("MAX (DRAWINGS_Id)", "");
            if (object.ReferenceEquals(objValue, DBNull.Value)) {
              PID = 0;
            } else {
              PID = Conversions.ToInteger(objValue) + 1;//JMR -- changed Int to Conversions.ToInteger

            }
          } else {
            FOUNDROWS2 = dsf.Tables["DRAWINGS"].Select("PLCDATASET_ID ='" + plcid + "' AND DESCRIPTION ='HARNESS'");

            drt = FOUNDROWS2[0];
            PID = Conversions.ToInteger(drt[4]);
          }
          string oldd = "";
          string newd = "";
          //oldd = Module1.newModule.OldHarnessPTP.Substring(Module1.newModule.OldHarnessPTP.IndexOf("-") + 1.ToString().Trim());//JMR -- look at -- can be changed to oldd = Module1.newModule.OldHarnessPTP.Substring(Module1.newModule.OldHarnessPTP.IndexOf("-") + 1).ToString().Trim(); to fix it, but not sure how to fix the line under this one -- changed to line below
          oldd = Module1.newModule.OldHarnessPTP.Substring(Module1.newModule.OldHarnessPTP.IndexOf("-") + 1).ToString().Trim();
          //newd = Module1.newModule.NewHarnessPTP.Substring(Module1.newModule.NewHarnessPTP.IndexOf("-").ToString().Trim() + 1);//JMR -- DEV -- Look at -- changed to line below
          newd = Module1.newModule.NewHarnessPTP.Substring(Module1.newModule.NewHarnessPTP.IndexOf("-") + 1).ToString().Trim();
          if (oldd == newd + "99") {
            oldd = newd;
          }
          dsf.Tables["DRAWINGS"].Rows.Add(Module1.newModule.NewHarnessPTP.Substring(0, Module1.newModule.NewHarnessPTP.IndexOf("-")).ToString().Trim(), oldd, newd, "HARNESS", PID, plcid);

        } catch (Exception ex) {

        }
        string str8;
        DataRow ROQW;
        int k = 0;
        int n = 0;
        int num9 = 0;
        int num10 = 0;
        string str;
        string str4;
        int num;
        string str5;
        SaveFileDialog dialog = new SaveFileDialog();
        xrParts parts = new xrParts();

        DataSet set4 = new DataSet();
        DataSet set7 = new DataSet();
        DataSet set8 = new DataSet();
        int num14 = 0;
        int num15 = 0;

        // GET ADDITIONAL PARTS AND WIRES FROM HARNESS
        DataSet WIREDS = new DataSet();
        int j = 0;
        int m = 0;
        if (ASSYDS.Tables[0].Rows[kl]["genPlannumber"].ToString().StartsWith("50")) {
          string str6 = "A";
          data2.ExecuteSQL(("UPDATE TBLCONT SET bacWireSpec ='',bacBraid ='' WHERE BACPLID ='" + this.PLANNUMBER + "'"));
          clsData data3 = new clsData();
          data3.ExecuteSQL(("UPDATE TBLCONT SET bacLength ='9992' WHERE bacWireNo LIKE '%SH%' AND bacPlId ='" + this.PLANNUMBER + "'"));

          set6 = data2.getData(("SELECT * FROM TBLCONT WHERE (BACWIRENO  LIKE '%%') AND ((BACREFDES1 LIKE '%WT%') or (BACREFDES2 LIKE '%WT%') or (BACREFDES1 LIKE '%NEAR%') or (BACREFDES2 LIKE '%NEAR%')) AND BACPLID ='" + this.PLANNUMBER + "'"));
          int num24 = (set6.Tables[0].Rows.Count - 1);
          j = 0;
          while ((j <= num24)) {



            str = Conversions.ToString(set6.Tables[0].Rows[j][1]);
            string str2 = Conversions.ToString(set6.Tables[0].Rows[j][5]);
            string str3 = str;
            str4 = str2;
            if (str.Contains("NEAR")) {
              str = str.Substring((str.IndexOf("(") + 5));
              str = str.Substring(0, str.IndexOf(")")).Trim();
              data3.ExecuteSQL(string.Concat(new string[] {
                "UPDATE TBLCONT SET BACREFDES1 ='",
                str,
                "' WHERE BACWIRENO LIKE '%-1' AND BACREFDES1 ='",
                str3,
                "' AND bacPlId ='",
                this.PLANNUMBER,
                "'"
              }));
            } else {
              if (str2.Contains("NEAR")) {
                str2 = str2.Substring((str2.IndexOf("(") + 5)).Trim();
                str2 = str2.Substring(0, str2.IndexOf(")")).Trim();
              }

              data3.ExecuteSQL(string.Concat(new string[] {
                "UPDATE TBLCONT SET BACREFDES2 ='",
                str2,
                "' WHERE BACWIRENO LIKE '%-1' AND BACREFDES2 ='",
                str4,
                "' AND bacPlId ='",
                this.PLANNUMBER,
                "'"
              }));


            }
            j += 1;
          }

          //'

          aset = data2.getData(("SELECT * FROM TBLCONT WHERE  (BACPIN1 NOT LIKE '%S7%') AND (BACPIN2 NOT LIKE'%S7%')AND (BACWIRENO NOT LIKE'%WHT%') AND (BACWIRENO NOT LIKE'%BLK%') AND bacPlId ='" + this.PLANNUMBER + "' AND bacAction ='ADD' ORDER BY bacwireno,bacBraid,bacRefdes1,BACREFDES2,BACLENGTH"));
          int num25;

          num25 = (aset.Tables[0].Rows.Count - 1);
          k = 0;
          string str14;
          string str15;
          string str16 = "";
          string str17 = "";//JMR -- DEV -- nulled it


          while ((k <= num25)) {

            if ((k == 0)) {
              str14 = Conversions.ToString(aset.Tables[0].Rows[k][1]);
              str15 = Conversions.ToString(aset.Tables[0].Rows[k][5]);
              str16 = str14;
              str17 = str15;
            } else {
              str14 = Conversions.ToString(aset.Tables[0].Rows[k][1]);
              str15 = Conversions.ToString(aset.Tables[0].Rows[k][5]);
            }
            int index = Module1.newModule.OldHarnessPTP.IndexOf("-");
            if ((((str14 != str16) || (str15 != str17)) || (k == 0))) {
              string str13;
              if ((k == 0)) {
                set2 = data2.getData(string.Concat(new string[] {
                  "select distinct(left(bacwireno,",
                  Conversions.ToString(index),
                  ")) from tblcont WHERE bacWireSpec ='' and baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                  str14,
                  "' AND BACREFDES2 ='",
                  str15,
                  "' AND BACPLID ='",
                  this.PLANNUMBER,
                  "'"
                }));
                if (((set2.Tables[0].Rows.Count == 1) | (set2.Tables[0].Rows.Count == 0))) {
                  try {
                    str13 = Conversions.ToString(set2.Tables[0].Rows[0][0]);
                  } catch (Exception exception1) {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    ProjectData.ClearProjectError();
                  }

                  data2.ExecuteSQL(string.Concat(new string[] {
                    "UPDATE TBLCONT SET bacWireSpec ='",
                    str14,
                    " - ",
                    str15,
                    "' WHERE baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                    str14,
                    "' AND BACREFDES2 ='",
                    str15,
                    "' AND BACPLID ='",
                    this.PLANNUMBER,
                    "'"
                  }));
                  data2.ExecuteSQL(string.Concat(new string[] {
                    "UPDATE TBLCONT SET bacBraid ='A' WHERE BACREFDES1 ='",
                    str14,
                    "' AND BACREFDES2 ='",
                    str15,
                    "' AND BACPLID ='",
                    this.PLANNUMBER,
                    "'"
                  }));
                } else {
                  data2.ExecuteSQL(string.Concat(new string[] {
                    "UPDATE TBLCONT SET bacWireSpec ='",
                    str14,
                    " - ",
                    str15,
                    "' WHERE baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                    str14,
                    "' AND BACREFDES2 ='",
                    str15,
                    "' AND BACPLID ='",
                    this.PLANNUMBER,
                    "'"
                  }));
                  data2.ExecuteSQL(string.Concat(new string[] {
                    "UPDATE TBLCONT SET bacBraid ='B' WHERE BACREFDES1 ='",
                    str14,
                    "' AND BACREFDES2 ='",
                    str15,
                    "' AND BACPLID ='",
                    this.PLANNUMBER,
                    "'"
                  }));
                  str6 = Conversions.ToString(Strings.Chr((Strings.Asc(str6) + 1)));
                }
              } else {
                set2 = data2.getData(string.Concat(new string[] {
                  "select distinct(left(bacwireno,",
                  Conversions.ToString(index),
                  ")) from tblcont WHERE bacWireSpec ='' and baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                  str14,
                  "' AND BACREFDES2 ='",
                  str15,
                  "' AND BACPLID ='",
                  this.PLANNUMBER,
                  "'"
                }));
                if ((set2.Tables[0].Rows.Count != 0)) {
                  str13 = Conversions.ToString(set2.Tables[0].Rows[0][0]);
                  if ((set2.Tables[0].Rows.Count == 1)) {
                    data2.ExecuteSQL(string.Concat(new string[] {
                      "UPDATE TBLCONT SET bacWireSpec ='",
                      str14,
                      " - ",
                      str15,
                      "' WHERE baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                      str14,
                      "' AND BACREFDES2 ='",
                      str15,
                      "' AND BACPLID ='",
                      this.PLANNUMBER,
                      "'"
                    }));
                    data2.ExecuteSQL(string.Concat(new string[] {
                      "UPDATE TBLCONT SET bacBraid ='A' WHERE BACREFDES1 ='",
                      str14,
                      "' AND BACREFDES2 ='",
                      str15,
                      "' AND BACPLID ='",
                      this.PLANNUMBER,
                      "'"
                    }));
                  } else {
                    if ((str6 == "W")) {
                      str6 = "A";
                      Module1.newModule.flag = true;
                    } else if (Module1.newModule.flag) {
                      str6 = Conversions.ToString(Strings.Chr((Strings.Asc(str6) + 1)));
                    } else {
                      str6 = Conversions.ToString(Strings.Chr((Strings.Asc(str6) + 1)));
                    }
                    if (Module1.newModule.flag) {
                      data2.ExecuteSQL(string.Concat(new string[] {
                        "UPDATE TBLCONT SET bacWireSpec ='",
                        str14,
                        " - ",
                        str15,
                        "' WHERE baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                        str14,
                        "' AND BACREFDES2 ='",
                        str15,
                        "' AND BACPLID ='",
                        this.PLANNUMBER,
                        "'"
                      }));
                      data2.ExecuteSQL(string.Concat(new string[] {
                        "UPDATE TBLCONT SET bacBraid ='A",
                        str6,
                        "' WHERE BACREFDES1 ='",
                        str14,
                        "' AND BACREFDES2 ='",
                        str15,
                        "' AND BACPLID ='",
                        this.PLANNUMBER,
                        "'"
                      }));
                    } else {
                      data2.ExecuteSQL(string.Concat(new string[] {
                        "UPDATE TBLCONT SET bacWireSpec ='",
                        str14,
                        " - ",
                        str15,
                        "' WHERE baclength NOT IN('9992','WIRE MARKER') and BACREFDES1 ='",
                        str14,
                        "' AND BACREFDES2 ='",
                        str15,
                        "' AND BACPLID ='",
                        this.PLANNUMBER,
                        "'"
                      }));
                      data2.ExecuteSQL(string.Concat(new string[] {
                        "UPDATE TBLCONT SET bacBraid ='",
                        str6,
                        "' WHERE BACREFDES1 ='",
                        str14,
                        "' AND BACREFDES2 ='",
                        str15,
                        "' AND BACPLID ='",
                        this.PLANNUMBER,
                        "'"
                      }));
                    }
                  }
                }
              }
            }
            str16 = str14;
            str17 = str15;
            k += 1;
          }
          m = 0;

          data2.ExecuteSQL(("UPDATE TBLCONT SET bacWireSpec ='A' WHERE baclength NOT IN('9992','WIRE MARKER') and ((BACREFDES1 LIKE'%WT%') and (BACREFDES2 LIKE '%WT%')) AND BACPLID ='" + this.PLANNUMBER + "'"));
          data2.ExecuteSQL(("UPDATE TBLCONT SET bacBraid ='A' WHERE ((BACREFDES1 LIKE'%WT%') OR (BACREFDES2 LIKE '%WT%')) AND BACPLID ='" + this.PLANNUMBER + "'"));
          aset = data.getData(string.Concat(new string[] {
            "SELECT DISTINCT bacBraid,(bacWireNo),bacLength,bacWireSpec,WIRE_SPEC_GAGE ,bacPlId,WIRE_CABLE_CD FROM TBLCONT,PTP WHERE   bacPlId ='",
            this.PLANNUMBER,
            "' AND bacAction ='ADD' AND ((BACWIRENO NOT LIKE'%WHT%') AND (BACWIRENO NOT LIKE'%BLK%')) and bacWireno = WIRE_NUMBER and PART_NUMBER ='",
            Module1.newModule.NewHarnessPTP,
            "' order by bacwireno"
          }));
          DataSet ASTR = new DataSet();
          //    Dim sourceR As DataRow() = aset.Tables.Item(0).[Select]("BACREFDES1= BACREFDES2 AND BACLENGTH NOT LIKE 'WIRE%' AND (BACPIN1 NOT LIKE '%S7%') AND (BACPIN2 NOT LIKE'%S7%') AND (BACWIRENO NOT LIKE'%WHT%') AND (BACWIRENO NOT LIKE'%BLK%') AND bacPlId ='" & Me.PlanNumber & "' AND bacAction ='ADD'")
          ASTR = data2.getData(("SELECT * FROM  TBLCONT WHERE  BACREFDES1= BACREFDES2 AND BACLENGTH NOT LIKE 'WIRE%' AND (BACPIN1 NOT LIKE '%S7%') AND (BACPIN2 NOT LIKE'%S7%') AND (BACWIRENO NOT LIKE'%WHT%') AND (BACWIRENO NOT LIKE'%BLK%') AND bacPlId ='" + this.PLANNUMBER + "' AND bacAction ='ADD' ORDER BY bacBraid,bacRefdes1,BACREFDES2,BACLENGTH "));
          for (int LKJ = 0; LKJ <= ASTR.Tables[0].Rows.Count - 1; LKJ++) {
            string WI;
            WI = ASTR.Tables[0].Rows[LKJ]["BACWIRENO"].ToString();

            DataRow[] sourceR = aset.Tables[0].Select("bacWIRENO ='" + WI + "'");
            ROW = sourceR[0];
            ROW[0] = "X";
            ROW[2] = "12";

          }
          source = aset.Tables[0].Select("bacLength ='9992'");
          int num26 = (source.Count() - 1);
          m = 0;
          while ((m <= num26)) {
            ROW = source[m];
            ROW[2] = "";
            ROW[3] = "";
            ROW[4] = "";
            m += 1;
          }
          source = aset.Tables[0].Select("bacLength = '0012'");
          int num27 = (source.Count() - 1);
          n = 0;
          while ((n <= num27)) {
            ROW = source[n];
            string GHJ;
            GHJ = ROW[3].ToString();
            try {
              if (GHJ.Contains("WT")) {
                ROW[3] = "X";
                ROW[0] = "X";
              } else if (GHJ.Contains("-")) {
                if (GHJ.Substring(0, GHJ.IndexOf("-")) == GHJ.Substring(GHJ.IndexOf("-") - 1).Trim()) {
                  ROW[3] = "X";
                  ROW[0] = "X";
                } else {
                  ROW[0] = "A";
                }
              } else {
                ROW[0] = "A";
              }
            } catch (Exception ex) {

            }

            n += 1;
          }
          source = aset.Tables[0].Select("bacLength = '0010'");
          num27 = (source.Count() - 1);
          n = 0;
          while ((n <= num27)) {
            ROW = source[n];
            string GHJ;
            GHJ = ROW[3].ToString();
            try {
              if (GHJ.Contains("WT")) {
                ROW[3] = "X";
                ROW[0] = "X";
              } else if (GHJ.Contains("-")) {
                if (GHJ.Substring(0, GHJ.IndexOf("-")) == GHJ.Substring(GHJ.IndexOf("-") - 1).Trim()) {
                  ROW[3] = "X";
                  ROW[0] = "X";
                } else {
                  ROW[0] = "A";
                }
              } else {
                ROW[0] = "A";
              }
            } catch (Exception ex) {

            }

            n += 1;
          }
          source = aset.Tables[0].Select("bacLength = '10'");
          num27 = (source.Count() - 1);
          n = 0;
          while ((n <= num27)) {
            ROW = source[n];
            string GHJ;
            GHJ = ROW[3].ToString();
            try {
              if (GHJ.Contains("WT")) {
                ROW[3] = "X";
                ROW[0] = "X";
              } else if (GHJ.Contains("-")) {
                if (GHJ.Substring(0, GHJ.IndexOf("-")) == GHJ.Substring(GHJ.IndexOf("-") - 1).Trim()) {
                  ROW[3] = "X";
                  ROW[0] = "X";
                } else {
                  ROW[0] = "X";
                }
              } else {
                ROW[0] = "A";
              }
            } catch (Exception ex) {

            }

            n += 1;
          }
          source = aset.Tables[0].Select("bacLength = '12'");
          num27 = (source.Count() - 1);
          n = 0;
          while ((n <= num27)) {
            ROW = source[n];
            string GHJ;
            GHJ = ROW[3].ToString();
            try {
              if (GHJ.Contains("WT")) {
                ROW[3] = "X";
                ROW[0] = "X";
              } else if (GHJ.Contains("-")) {
                if (GHJ.Substring(0, GHJ.IndexOf("-")) == GHJ.Substring(GHJ.IndexOf("-") - 1).Trim()) {
                  ROW[3] = "X";
                  ROW[0] = "X";
                } else {
                  ROW[0] = "X";
                }
              } else {
                ROW[0] = "A";
              }
            } catch (Exception ex) {

            }

            n += 1;
          }
          source = aset.Tables[0].Select("bacLength ='WIRE MARKER'");
          int num28 = (source.Count() - 1);
          num9 = 0;
          while ((num9 <= num28)) {
            ROW = source[num9];

            ROW[4] = "";
            ROW[3] = "X";
            ROW[0] = "X";

            num9 += 1;
          }
          source = aset.Tables[0].Select("bacLength ='9998'");
          int num29 = (source.Count() - 1);
          num10 = 0;
          while ((num10 <= num29)) {
            ROW = source[num10];
            ROW[2] = "WIRE MARKER";
            ROW[3] = "X";
            ROW[0] = "X";
            ROW[4] = "";
            num10 += 1;
          }
          source = aset.Tables[0].Select("bacLength ='WIRE MARKER' and bacWireNo like '%SH%'");
          int num30 = (source.Count() - 1);
          int num11 = 0;
          while ((num11 <= num30)) {
            ROW = source[num11];
            ROW[3] = "";
            num11 += 1;
          }
          DataSet set5 = new DataSet();
          source = aset.Tables[0].Select("WIRE_SPEC_GAGE <>''");
          int num31 = (source.Count() - 1);
          int num12 = 0;
          while ((num12 <= num31)) {
            ROW = source[num12];
            string str10 = Conversions.ToString(ROW[4]);
            if ((str10 == "C4928-20")) {
            }
            set5 = data.getData(("SELECT * FROM PDFWIRE1 WHERE wspecOld ='" + str10 + "'"));
            if ((set5.Tables[0].Rows.Count != 0)) {
              string str9 = Conversions.ToString(set5.Tables[0].Rows[0][1]);
              ROW[4] = str9;
            }
            num12 += 1;
          }
          aset.Tables[0].Columns.Add("LWA_LENGTH");
          aset.Tables[0].Columns["LWA_LENGTH"].SetOrdinal(5);
          source = aset.Tables[0].Select("bacBraid<>'A' and bacBraid<>'X'");
          int num32 = (source.Count() - 1);
          int num13 = 0;
          while ((num13 <= num32)) {
            ROW = source[num13];
            str5 = Conversions.ToString(ROW[0]);

            str8 = Conversions.ToString(ROW[2]);
            if (!(((str8 == "") | (str8 == null)) | (str8 == "WIRE MARKER"))) {
              str8 = Conversions.ToString(data2.getData(string.Concat(new string[] {
                "SELECT MAX(BACLENGTH) FROM TBLCONT WHERE BACLENGTH <>'WIRE MARKER' AND BACLENGTH <>'9992' AND BACLENGTH <>'9998' AND BACPLID ='",
                this.PLANNUMBER,
                "' AND BACBRAID ='",
                str5,
                "'"
              })).Tables[0].Rows[0][0]);
              try {
                str8 = Operators.AddObject(Conversion.Int(str8), 100).ToString().PadLeft(4, '0');
              } catch (Exception exception6) {
                ProjectData.SetProjectError(exception6);
                Exception exception2 = exception6;
                ProjectData.ClearProjectError();
              }
            }
            ROW[0] = ("Group " + str5 + " : Braid  together");
            ROW[5] = str8;
            num13 += 1;
          }
          source = aset.Tables[0].Select("bacBraid='A'");
          int num33 = (source.Count() - 1);
          num14 = 0;
          while ((num14 <= num33)) {
            ROW = source[num14];
            str8 = Conversions.ToString(ROW[2]);
            try {
              str8 = Operators.AddObject(Conversion.Int(str8), 100).ToString().PadLeft(4, '0');
            } catch (Exception exception7) {
              ProjectData.SetProjectError(exception7);
              Exception exception3 = exception7;
              ProjectData.ClearProjectError();
            }
            ROW[5] = str8;
            str5 = Conversions.ToString(ROW[0]);
            ROW[0] = ("Group " + str5 + " : Braid  Seperately");
            num14 += 1;
          }
          source = aset.Tables[0].Select("bacBraid='X'");
          int num34 = (source.Count() - 1);
          num15 = 0;
          while ((num15 <= num34)) {
            ROW = source[num15];
            str8 = Conversions.ToString(ROW[2]);
            try {
              str8 = Operators.AddObject(Conversion.Int(str8), 100).ToString().PadLeft(4, '0');
            } catch (Exception exception8) {
              ProjectData.SetProjectError(exception8);
              Exception exception4 = exception8;
              str8 = str8;
              ProjectData.ClearProjectError();
            }
            ROW[5] = str8;
            str5 = Conversions.ToString(ROW[0]);
            ROW[0] = ("Group " + str5 + " : No Braid");
            num15 += 1;
          }

          source = aset.Tables[0].Select("bacBraid like 'Group A%' and bacWireNo like '%-1'");
          num34 = (source.Count() - 1);
          num15 = 0;
          while ((num15 <= num34)) {
            ROW = source[num15];
            str8 = Conversions.ToString(ROW[1]);

            try {
              DataRow[] source2QW;

              source2QW = aset.Tables[0].Select("bacBraid NOT like 'Group A%' and bacWireNo = '" + str8.Substring(0, str8.Length - 1) + "2'");
              ROQW = source2QW[0];
              ROQW[0] = ("Group A : Braid  Seperately");
              try {
                DataSet DFD = new DataSet();
                DFD = data2.getData("SELECT BASEREF FROM TBLREFDES WHERE REFPLANID ='" + PLANNUMBER + "' AND REFDES IN (SELECT SREFDES AS REFDES FROM TBLWIRES WHERE SREFDES LIKE '%WT%' AND WIRENO ='" + str8 + "' AND WIRESPLID ='" + PLANNUMBER + "')");
                string GFH;
                GFH = DFD.Tables[0].Rows[0][0].ToString();
                ROW[3] = ROW[3] + " (NEAR " + GFH + ")";
              } catch (Exception ex) {

              }
              //   row.Item(5) = 


            } catch (Exception exception8) {
              ProjectData.SetProjectError(exception8);
              Exception exception4 = exception8;
              //   str8 = str8
              ProjectData.ClearProjectError();
            }
            try {
              DataRow[] source2QW;

              source2QW = aset.Tables[0].Select("bacBraid NOT like 'Group A%' and bacWireNo = '" + str8.Substring(0, str8.Length - 1) + "3'");
              ROQW = source2QW[0];
              ROQW[0] = ("Group A : Braid  Seperately");



            } catch (Exception exception8) {
              ProjectData.SetProjectError(exception8);
              Exception exception4 = exception8;
              //   str8 = str8
              ProjectData.ClearProjectError();
            }


            num15 += 1;
          }
          try {
            source = aset.Tables[0].Select("bacBraid like 'Group  : Braid  together' and bacWireNo like '%SH%'");
            num34 = (source.Count() - 1);
            num15 = 0;
            while ((num15 <= num34)) {
              ROW = source[num15];
              str8 = Conversions.ToString(ROW[1]);
              str8 = str8.Substring(0, (str8.Length - 5));
              DataSet DF = new DataSet();
              DataRow[] source2QW;
              source2QW = aset.Tables[0].Select("bacBraid NOT like 'Group  : Braid  together' and bacWireNo like '" + str8 + "%'");
              string FHG;
              DataRow ROWD;
              ROWD = source2QW[0];
              FHG = Conversions.ToString(ROWD[0]);
              ROW[0] = FHG;
              num15 += 1;
              aset.AcceptChanges();

            }
          } catch (Exception ex) {

          }
        }


        WIREDS = data.getData(string.Concat(new string[] {
          "SELECT DISTINCT (bacWireNo),bacLength,WIRE_SPEC_GAGE,bacPlId,WIRE_CABLE_CD,bacbraid FROM TBLCONT,PTP WHERE   bacPlId ='",
          sapPlid,
          "' AND ((bacAction ='ADD')or(bacaction ='REMOVE')) and bacWireno = WIRE_NUMBER and PART_NUMBER ='",
          harnessname,
          "'"
        }));
        source = WIREDS.Tables[0].Select("bacLength ='9992'");
        num14 = (source.Count() - 1);
        int i = 0;
        while ((i <= num14)) {
          ROW = source[i];
          ROW[1] = "";
          ROW[2] = "";
          i += 1;
        }
        source = WIREDS.Tables[0].Select("bacLength ='WIRE MARKER' and bacWireNo like '%SH%'");
        num15 = (source.Count() - 1);
        j = 0;
        while ((j <= num15)) {
          ROW = source[j];
          ROW[2] = "";
          j += 1;
        }


        source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE <>''");
        int num16 = (source.Count() - 1);
        k = 0;
        while ((k <= num16)) {
          ROW = source[k];
          set6 = data.getData(("SELECT * FROM PDFWIRE1 WHERE wspecOld ='" + Conversions.ToString(ROW[2]) + "'"));
          if ((set6.Tables[0].Rows.Count != 0)) {
            string str2 = Conversions.ToString(set6.Tables[0].Rows[0][1]);
            ROW[2] = str2;
          }
          k += 1;
        }
        source = WIREDS.Tables[0].Select("bacLength ='WIRE MARKER'");
        int num17 = (source.Count() - 1);
        m = 0;
        while ((m <= num17)) {
          ROW = source[m];
          ROW[2] = "";
          m += 1;
        }
        source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-20'");
        int num18 = (source.Count() - 1);
        n = 0;
        while ((n <= num18)) {
          ROW = source[n];
          ROW[2] = "M22759/91-20-9";
          n += 1;
        }
        source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-22'");
        int num19 = (source.Count() - 1);
        int num7 = 0;
        while ((num7 <= num19)) {
          ROW = source[num7];
          ROW[2] = "M22759/91-22-9";
          num7 += 1;
        }
        source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-24'");
        int num20 = (source.Count() - 1);
        int num8 = 0;
        while ((num8 <= num20)) {
          ROW = source[num8];
          ROW[2] = "M22759/81-24-9";
          num8 += 1;
        }
        source = WIREDS.Tables[0].Select("WIRE_SPEC_GAGE ='C4928-26'");
        int num21 = (source.Count() - 1);
        num9 = 0;
        while ((num9 <= num21)) {
          ROW = source[num9];
          ROW[2] = "C20805-26";
          num9 += 1;
        }
        source = WIREDS.Tables[0].Select("bacLength ='9998'");
        int num211 = (source.Count() - 1);
        int num91 = 0;
        while ((num91 <= num211)) {
          ROW = source[num91];
          ROW[1] = "WIRE MARKER";
          num91 += 1;
        }
        source = WIREDS.Tables[0].Select("bacWIRENO LIKE '%WHT%'");
        int num2111 = (source.Count() - 1);
        int num911 = 0;
        while ((num911 <= num2111)) {
          ROW = source[num911];
          WIREDS.Tables[0].Rows.Remove(ROW);
          num911 += 1;
        }
        source = WIREDS.Tables[0].Select("bacWIRENO LIKE '%BLK%'");
        int num22111 = (source.Count() - 1);
        int num9211 = 0;
        while ((num9211 <= num22111)) {
          ROW = source[num9211];
          WIREDS.Tables[0].Rows.Remove(ROW);
          num9211 += 1;
        }
        DataRow[] sourceA = WIREDS.Tables[0].Select("bacLength ='REF'");
        int num14A = (sourceA.Count() - 1);
        int iA = 0;
        while ((iA <= num14A)) {
          ROW = sourceA[iA];
          ROW[1] = "";
          ROW[2] = "";
          iA += 1;
        }
        //ADD WIRES TO SAP
        string HARNESSSYNTH = "'";
        DataSet SYNTHDS = new DataSet();
        SYNTHDS = data.getData("SELECT * FROM TBLGENERAL WHERE GENPLID ='" + sapPlid + "'");
        if (SYNTHDS.Tables[0].Rows.Count == 0) {

        } else {
          try {
            HARNESSSYNTH = SYNTHDS.Tables[0].Rows[0]["genPdf1"].ToString();
            HARNESSSYNTH = harnessname.Substring(0, harnessname.IndexOf("-")) + "-" + HARNESSSYNTH;
          } catch (Exception ex) {
            HARNESSSYNTH = harnessname.Substring(0, harnessname.IndexOf("-")) + "-TBD";
          }

        }
        WIREDS.AcceptChanges();

        source = WIREDS.Tables[0].Select("bacWIRENO LIKE '%%'");
        int num222111 = (source.Count() - 1);
        int num92211 = 0;
        while ((num92211 <= num222111)) {
          ROW = source[num92211];

          string wirestr = "";
          if (ROW[1].ToString().Contains("MARKER")) {
            ROW[0] = ROW[0] + " (REF)";
            ROW[2] = "WIRE MARKER";
          }
          if (ROW[2] == "") {
            wirestr = "";
          } else if (ROW[2].ToString().Contains("MARKER")) {
            wirestr = ROW[2].ToString();
          } else {

            wirestr = "WIRE (" + ROW[2] + ")";
          }








          if (ROW[0].ToString().Contains("SH") | ROW[0].ToString().EndsWith("-2") | ROW[0].ToString().EndsWith("-3") | ROW[0].ToString().EndsWith("-4") | ROW[0].ToString().EndsWith("-5")) {
            ROW[1] = "";
            ROW[2] = "9992";
          }
          string wl = "";

          try {
            //wl = Int(ROW.Item(1)); //JMR -- look at -- why cast type it to Int when setting it to a string?
              wl = ROW.ItemArray[1].ToString();//I'm assuming this is what the line above is suppose to be
          } catch (Exception ex) {
            wl = "";
          }
          dsf.Tables["wires"].Rows.Add(ROW[0], ROW[4], ROW[2], wl, ROW[5], "ADD", PID);




          // aset.Tables(0).Rows.Add(sapPlid, HARNESSSYNTH, 1, ROW.Item(0), wirestr, drawingnum, "-", "ADD")
          num92211 += 1;
        }
        // dsf.WriteXml(Application.StartupPath & "\NICK.XML")

        DataSet PARTSDS = new DataSet();
        PARTSDS = data.getData(("SELECT * FROM TBLREFDESCOMP WHERE REFCOMPPLID ='" + sapPlid + "' AND REFACTION ='ADD'"));
        int num22 = (aset.Tables[0].Rows.Count - 1);
        // ADD PARTS TO SAP
        source = PARTSDS.Tables[0].Select("PARTNUMBER LIKE '%%'");
        int numP = (source.Count() - 1);
        int numX = 0;
        while ((numX <= numP)) {



          // FOUNDROWS2 = 
          object objValue;


          objValue = dsf.Tables["PARTS"].Compute("MAX (PARTS_Id)", "");
          if (object.ReferenceEquals(objValue, DBNull.Value)) {
            PRTID = 0;
          } else {
            PRTID = Conversions.ToInteger(objValue) + 1;//JMR -- changed Int to Conversions.ToInteger

          }
          ROW = source[numX];
          if (drt[0].ToString().StartsWith("P5374")) {
          } else if (drt[0].ToString().StartsWith("P5373")) {

          } else {
            dsf.Tables["parts"].Rows.Add(ROW[0], ROW[1], ROW[2], ROW[4], "", ROW[3], PRTID, PID);

          }
          numX += 1;

        }
        //  dsf.WriteXml(Application.StartupPath & "\NICK.XML")

        //





      }
      try {
        FOUNDROWS2 = dsf.Tables["TVES"].Select(("PLCDATASET_ID =" + plcid + ""));
        if (FOUNDROWS2.Count() == 0) {
          dsf.Tables["TVES"].Rows.Add(Module1.newModule.KCLTV, KCLFROM, Module1.newModule.KCLENDS, System.DBNull.Value, System.DBNull.Value, plcid);

        } else {

        }
      } catch (Exception ex) {

      }

      try {
        FOUNDROWS2 = dsf.Tables["PARTS"].Select(("QTY ='" + "AR" + "'"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3[2] = "9998";

          }
        }
      } catch (Exception ex) {

      }
      try {
        FOUNDROWS2 = dsf.Tables["PARTS"].Select(("QTY ='" + "REF" + "'"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3[2] = "9998";

          }
        }
      } catch (Exception ex) {

      }
      try {
        FOUNDROWS2 = dsf.Tables["PARTS"].Select(("location =''"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3[3] = System.DBNull.Value.ToString();

          }
        }
      } catch (Exception ex) {

      }
      try {
        FOUNDROWS2 = dsf.Tables["PARTS"].Select(("dwg_zone =''"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3[4] = System.DBNull.Value.ToString();

          }
        }
      } catch (Exception ex) {

      }
      try {
        FOUNDROWS2 = dsf.Tables["wires"].Select(("wire_len =''"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3[3] = "9998";
          }
        }
      } catch (Exception ex) {

      }
      try {
        FOUNDROWS2 = dsf.Tables["wires"].Select(("wire_spec =''"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3[2] = "9992";
          }
        }
      } catch (Exception ex) {

      }
      try {
        FOUNDROWS2 = dsf.Tables["parts"].Select(("LOCATION ='-'"));

        if (FOUNDROWS2.Count() == 0) {

        } else {
          for (int AR = 0; AR <= FOUNDROWS2.Count(); AR++) {
            drt3 = FOUNDROWS2[AR];
            drt3["LOCATION"] = System.DBNull.Value.ToString();
          }
        }
      } catch (Exception ex) {
      }

      SaveFileDialog Sdialog = new SaveFileDialog { Filter = "xml files (*.xml)|*.xml" };
      Sdialog.FileName = "PLC_" + cmbTail.Text;

      if ((Sdialog.ShowDialog() == DialogResult.OK)) {
        ListBoxControl1.BringToFront();
        ListBoxControl1.Items.Clear();

        string fileName = Sdialog.FileName;
        dsf.WriteXml(fileName);
        XmlDocument myDocument = new XmlDocument();
        myDocument.Load(fileName);
        myDocument.Schemas.Add("", Application.StartupPath + "\\PLCSSchema.xsd");
        ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
        myDocument.Validate(eventHandler);
        if (m_Success == false) {
          ListBoxControl1.Items.Add("xml " + fileName + " is valid.");
          ListBoxControl1.Refresh();
          MessageBox.Show("xml " + fileName + " is valid.", "Validation", MessageBoxButtons.OK);
        } else {
          ListBoxControl1.Items.Add("xml " + fileName + " is not valid.");
          ListBoxControl1.Refresh();
        }
      }
    }

    private void ValidationEventHandler(object sender, ValidationEventArgs e)
    {
        //JMR -- look at -- added in the break statements
      switch (e.Severity) {
        case XmlSeverityType.Error:
          if (e.Message == "The identity constraint 'PARTSPK2' validation has failed. Either a key is missing or the existing key has an empty node.") {
              break;
          } else {
            m_Success = true;
            ListBoxControl1.Items.Add(e.Message);
            ListBoxControl1.Refresh();
            break;

          }
        case XmlSeverityType.Warning:
          Debug.WriteLine("Warning {0}", e.Message);
          break;
      }
    }



    private bool validateSchema(string infilename)
    {
      //this Function will validate the schema file (xsd)
      StreamReader sr = null;//JMR -- look at -- nulled it
      XmlSchema myschema;
      m_Success = true;
      try {
        sr = new StreamReader(infilename);
        myschema = XmlSchema.Read(sr, ValidationCallBack);
        //This compile statement is what ususally catches the errors
        myschema.Compile(ValidationCallBack);

      } finally {
        sr.Close();
      }
      return m_Success;
    }
    private bool validatexml(string infile)
    {
      //First we create the xmltextreader
      XmlTextReader xmlr = new XmlTextReader(infile);
      //We pass the xmltextreader into the xmlvalidatingreader
      //This will validate the xml doc with the schema file
      //NOTE the xml file it self points to the schema file
      XmlValidatingReader xmlvread = new XmlValidatingReader(xmlr);

      // Set the validation event handler
      xmlvread.ValidationEventHandler += ValidationCallBack;
      m_Success = true;

      // Read XML data
      while ((xmlvread.Read())) {
      }
      //Close the reader.
      xmlvread.Close();

      //The validationeventhandler is the only thing that would 
      //set m_Success to false
      return m_Success;
    }
    private void ValidationCallBack(object sender, ValidationEventArgs args)
    {
      //Display the validation error.  This is only called on error
      m_Success = false;
      MessageBox.Show("Validation error: " + args.Message);
    }
    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton5_Click(System.Object sender, System.EventArgs e)
    {
      //        ListBoxControl1.SendToBack()

      //        Dim data As New clsData
      //        Dim ROW As DataRow
      //        Dim aset As New DataSet
      //        Dim aset2 As New DataSet
      //        Dim ASET3 As New DataSet
      //        Dim dataSet As New DataSet
      //        Dim set2 As New DataSet
      //        Dim set3 As New DataSet
      //        Dim search As New frmSearch
      //        Dim QTYP As Integer = 0
      //        Dim QTYSTR As String = Nothing
      //        Dim source As DataRow()
      //        Dim expor As String
      //        Dim KCLK As String = Nothing
      //        QN = 0
      //        QR = 0
      //        Qseg = ""
      //        If cmbTail.Text = "" Then
      //            XtraMessageBox.Show("Please select a T/V", "MKPL")
      //            Exit Sub
      //        End If
      //        If ComboBoxEdit1.Text = "" Then
      //            XtraMessageBox.Show("Please select FROM", "MKPL")
      //            Exit Sub
      //        End If
      //        If ComboBoxEdit2.Text = "" Then
      //            XtraMessageBox.Show("Please select TO", "MKPL")
      //            Exit Sub
      //        End If
      //        KCLENDS = ComboBoxEdit2.Text
      //        KCLFROM = ComboBoxEdit1.Text

      //        Dim QTYYPSTR As String = Nothing
      //        expor = Guid.NewGuid.ToString
      //        Dim relasA As Boolean = False
      //        Dim ans As DialogResult
      //        RELAS = False
      //        ans = XtraMessageBox.Show("  Calculate MKPL Export", "MKPL", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3)
      //        If ans = Windows.Forms.DialogResult.Yes Then


      //        Else
      //            Exit Sub
      //        End If

      //        aset = data.getData(String.Concat(New String() {"select * from  tblAssembly where prtpartNumberDoc <>'' and prtaction <>'REINSTALL' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' ))) order by prtPartNumberDoc "}))
      //        aset.Tables(0).Columns.Add("LENGTH")
      //        aset.Tables(0).Columns.Add("LOCATION")
      //        aset.Tables(0).Columns.Add("sort")
      //        For t = 0 To aset.Tables(0).Rows.Count - 1
      //            aset.Tables(0).Rows(t).Item("sort") = aset.Tables(0).Rows(t).Item("prtEcp") & "-" & aset.Tables(0).Rows(t).Item("prtDash")
      //        Next
      //        Dim FOUNDROWS4() As Data.DataRow
      //        Dim drt As DataRow
      //        FOUNDROWS4 = aset.Tables(0).[Select](("prtEcp <> ''"))
      //        Dim num49 As Integer = (FOUNDROWS4.Count - 1)
      //        Dim i4 As Integer = 0
      //        Do While (i4 <= num49)
      //            drt = FOUNDROWS4(i4)
      //            drt.Item(1) = drt.Item(5) & "-" & drt.Item(1)
      //            i4 = i4 + 1

      //        Loop
      //        FOUNDROWS4 = aset.Tables(0).[Select](("prtEcp <> ''"))
      //        num49 = (FOUNDROWS4.Count - 1)
      //        i4 = 0
      //        Do While (i4 <= num49)
      //            Dim qtytotal As Integer = 0
      //            Dim duppart As String = ""
      //            Dim qtystring As String = ""
      //            Dim qty2string As String = ""
      //            Dim qty1 As Integer = 0
      //            Dim qty2 As Integer = 0
      //            Dim FOUNDROWStotal() As Data.DataRow
      //            Dim drtTotal As DataRow
      //            Dim totalDrwg As String = ""
      //            Dim totaldesc As String = ""
      //            Dim totalPLid As String = ""


      //            drt = FOUNDROWS4(i4)
      //            totalDrwg = drt.Item(1)
      //            duppart = drt.Item(3)
      //            qtystring = drt.Item(2)
      //            If qtystring = "AR" Then
      //                qty1 = 9992
      //            Else
      //                qty1 = drt.Item(2)
      //            End If

      //            totaldesc = drt.Item(4)
      //            totalPLid = drt.Item(0)
      //            Try
      //                FOUNDROWStotal = aset.Tables(0).[Select]("prtdash='" & totalDrwg & "' and prtPartNumberDoc ='" & duppart & "' and prtPlid<>'" & totalPLid & "' and prtDescription='" & totaldesc & "'")

      //            Catch ex As Exception

      //            End Try
      //            For g = 0 To FOUNDROWStotal.Count - 1
      //                Try
      //                    drtTotal = FOUNDROWStotal(g)
      //                    qty2string = drtTotal.Item(2)
      //                    If qty2string = "AR" Then
      //                        qty1 = 9992
      //                        drt.Item(2) = qty1
      //                        drtTotal.Item(2) = 3333
      //                    Else
      //                        qty2 = drtTotal.Item(2)
      //                        drt.Item(2) = qty1 + qty2
      //                        drtTotal.Item(2) = 3333
      //                    End If

      //                Catch ex As Exception

      //                End Try

      //            Next

      //            drt.Item(1) = drt.Item(5) & "-" & drt.Item(1)
      //            i4 = i4 + 1

      //        Loop
      //        aset.Tables(0).AcceptChanges()

      //        FOUNDROWS4 = aset.Tables(0).[Select]("prtQty ='3333'")
      //        num49 = (FOUNDROWS4.Count - 1)
      //        i4 = 0
      //        Do While (i4 <= num49)
      //            Dim delrow As DataRow

      //            drt = FOUNDROWS4(i4)
      //            Try
      //                aset.Tables(0).Rows.Remove(drt)

      //            Catch ex As Exception

      //            End Try
      //            i4 = i4 + 1

      //        Loop
      //        aset.AcceptChanges()
      //        Dim ASSYDS As New DataSet
      //        ASSYDS = data.getData(String.Concat(New String() {"select DISTINCT PRTECP from  tblAssembly where prtpartNumberDoc <>'' and prtaction ='ADD' and ((prtPartNumberDoc LIKE '%%')or (prtDescription LIKE '%%')) and ((prtTypeVer ='", KCLTV, "'and ", KCLENDS, " between prtFrom and prtThru ) or ( prtTypeVer = '999' and prtThru = 9999 )or ( prtTypeVer = '0' and prtThru = 0 )) and prtPlid in (SELECT GENPLID AS prtPlid FROM TBLGENERAL WHERE GENPLID IN ([select] efPlId as GENPLID from tblEffectivities where (efTypeVer ='", KCLTV, "' and (", KCLENDS, " between INT(efFrom ) and INT(efThru ) )) or ( efTypeVer = '999' and efThru like '999%' )))  "}))
      //        For kl = 0 To ASSYDS.Tables(0).Rows.Count - 1
      //            pr1.Properties.Maximum = ASSYDS.Tables(0).Rows.Count - 1
      //            pr1.EditValue = kl
      //            pr1.Refresh()
      //            Dim harnessname As String = ""
      //            Dim dsMPRS As New DataSet
      //            Dim drawingnum As String = ""
      //            drawingnum = ASSYDS.Tables(0).Rows(kl).Item(0)

      //            dsMPRS = data.getData("SELECT * FROM MPRS WHERE (" & KCLENDS & " between int(fr0m) and int(thru)) and tv ='" & KCLTV & "' and DWG ='" & drawingnum & "' AND APP='A' AND NOMEN LIKE 'WIRIN%' AND PART_NUMBER NOT IN(SELECT prtPartNumberDoc as PART_NUMBER FROM TBLASSEMBLY WHERE PRTACTION ='ADD')")
      //            If dsMPRS.Tables(0).Rows.Count <> 0 Then
      //                For hj = 0 To dsMPRS.Tables(0).Rows.Count - 1
      //                    harnessname = dsMPRS.Tables(0).Rows(hj).Item(4).trim
      //                    Dim harnds As New DataSet
      //                    Dim sapPlid As String = ""
      //                    harnds = data.getData("SELECT * FROM TBLSELHARNESS WHERE NEWHRN='" & harnessname & "'")
      //                    If harnds.Tables(0).Rows.Count = 0 Then
      //                        GoTo noharnpr
      //                    End If
      //                    sapPlid = harnds.Tables(0).Rows(0).Item(0)
      //                    ' GET ADDITIONAL PARTS AND WIRES FROM HARNESS
      //                    Dim WIREDS As New DataSet
      //                    WIREDS = data.getData(String.Concat(New String() {"SELECT DISTINCT (bacWireNo),bacLength,WIRE_SPEC_GAGE,bacPlId,WIRE_CABLE_CD FROM TBLCONT,PTP WHERE   bacPlId ='", sapPlid, "' AND ((bacAction ='ADD')or(bacaction ='REMOVE')) and bacWireno = WIRE_NUMBER and PART_NUMBER ='", harnessname, "'"}))
      //                    source = WIREDS.Tables.Item(0).[Select]("bacLength ='9992'")
      //                    Dim num14 As Integer = (source.Count() - 1)
      //                    Dim i As Integer = 0
      //                    Do While (i <= num14)
      //                        ROW = source(i)
      //                        ROW.Item(1) = ""
      //                        ROW.Item(2) = ""
      //                        i += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("bacLength ='WIRE MARKER' and bacWireNo like '%SH%'")
      //                    Dim num15 As Integer = (source.Count() - 1)
      //                    Dim j As Integer = 0
      //                    Do While (j <= num15)
      //                        ROW = source(j)
      //                        ROW.Item(2) = ""
      //                        j += 1
      //                    Loop
      //                    Dim set6 As New DataSet
      //                    source = WIREDS.Tables.Item(0).[Select]("WIRE_SPEC_GAGE <>''")
      //                    Dim num16 As Integer = (source.Count() - 1)
      //                    Dim k As Integer = 0
      //                    Do While (k <= num16)
      //                        ROW = source(k)
      //                        set6 = data.getData(("SELECT * FROM PDFWIRE1 WHERE wspecOld ='" & Conversions.ToString(ROW.Item(2)) & "'"))
      //                        If (set6.Tables.Item(0).Rows.Count <> 0) Then
      //                            Dim str2 As String = Conversions.ToString(set6.Tables.Item(0).Rows.Item(0).Item(1))
      //                            ROW.Item(2) = str2
      //                        End If
      //                        k += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("bacLength ='WIRE MARKER'")
      //                    Dim num17 As Integer = (source.Count() - 1)
      //                    Dim m As Integer = 0
      //                    Do While (m <= num17)
      //                        ROW = source(m)
      //                        ROW.Item(2) = ""
      //                        m += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("WIRE_SPEC_GAGE ='C4928-20'")
      //                    Dim num18 As Integer = (source.Count() - 1)
      //                    Dim n As Integer = 0
      //                    Do While (n <= num18)
      //                        ROW = source(n)
      //                        ROW.Item(2) = "M22759/91-20-9"
      //                        n += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("WIRE_SPEC_GAGE ='C4928-22'")
      //                    Dim num19 As Integer = (source.Count() - 1)
      //                    Dim num7 As Integer = 0
      //                    Do While (num7 <= num19)
      //                        ROW = source(num7)
      //                        ROW.Item(2) = "M22759/91-22-9"
      //                        num7 += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("WIRE_SPEC_GAGE ='C4928-24'")
      //                    Dim num20 As Integer = (source.Count() - 1)
      //                    Dim num8 As Integer = 0
      //                    Do While (num8 <= num20)
      //                        ROW = source(num8)
      //                        ROW.Item(2) = "M22759/81-24-9"
      //                        num8 += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("WIRE_SPEC_GAGE ='C4928-26'")
      //                    Dim num21 As Integer = (source.Count() - 1)
      //                    Dim num9 As Integer = 0
      //                    Do While (num9 <= num21)
      //                        ROW = source(num9)
      //                        ROW.Item(2) = "C20805-26"
      //                        num9 += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("bacLength ='9998'")
      //                    Dim num211 As Integer = (source.Count() - 1)
      //                    Dim num91 As Integer = 0
      //                    Do While (num91 <= num211)
      //                        ROW = source(num91)
      //                        ROW.Item(1) = "WIRE MARKER"
      //                        num91 += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("bacWIRENO LIKE '%WHT%'")
      //                    Dim num2111 As Integer = (source.Count() - 1)
      //                    Dim num911 As Integer = 0
      //                    Do While (num911 <= num2111)
      //                        ROW = source(num911)
      //                        WIREDS.Tables(0).Rows.Remove(ROW)
      //                        num911 += 1
      //                    Loop
      //                    source = WIREDS.Tables.Item(0).[Select]("bacWIRENO LIKE '%BLK%'")
      //                    Dim num22111 As Integer = (source.Count() - 1)
      //                    Dim num9211 As Integer = 0
      //                    Do While (num9211 <= num22111)
      //                        ROW = source(num9211)
      //                        WIREDS.Tables(0).Rows.Remove(ROW)
      //                        num9211 += 1
      //                    Loop
      //                    Dim sourceA As DataRow() = WIREDS.Tables.Item(0).[Select]("bacLength ='REF'")
      //                    Dim num14A As Integer = (sourceA.Count - 1)
      //                    Dim iA As Integer = 0
      //                    Do While (iA <= num14A)
      //                        ROW = sourceA(iA)
      //                        ROW.Item(1) = ""
      //                        ROW.Item(2) = ""
      //                        iA += 1
      //                    Loop
      //                    'ADD WIRES TO SAP
      //                    Dim HARNESSSYNTH As String = "'"
      //                    Dim SYNTHDS As New DataSet
      //                    SYNTHDS = data.getData("SELECT * FROM TBLGENERAL WHERE GENPLID ='" & sapPlid & "'")
      //                    If SYNTHDS.Tables(0).Rows.Count = 0 Then

      //                    Else
      //                        Try
      //                            HARNESSSYNTH = SYNTHDS.Tables(0).Rows(0).Item("genPdf1")
      //                            HARNESSSYNTH = harnessname.Substring(0, harnessname.IndexOf("-")) & "-" & HARNESSSYNTH
      //                        Catch ex As Exception
      //                            HARNESSSYNTH = harnessname.Substring(0, harnessname.IndexOf("-")) & "-TBD"
      //                        End Try

      //                    End If

      //                    source = WIREDS.Tables.Item(0).[Select]("bacWIRENO LIKE '%%'")
      //                    Dim num222111 As Integer = (source.Count() - 1)
      //                    Dim num92211 As Integer = 0
      //                    Do While (num92211 <= num222111)
      //                        ROW = source(num92211)

      //                        Dim wirestr As String = ""
      //                        If ROW.Item(1).ToString.Contains("MARKER") Then
      //                            ROW.Item(0) = ROW.Item(0) & " (REF)"
      //                            ROW.Item(2) = "WIRE MARKER"
      //                        End If
      //                        Try
      //                            aset.Tables(0).Columns.Add("LENGTH")

      //                        Catch ex As Exception

      //                        End Try
      //                        If ROW.Item(2) = "" Then
      //                            wirestr = ""
      //                        ElseIf ROW.Item(2).ToString.Contains("MARKER") Then
      //                            wirestr = ROW.Item(2)
      //                        Else

      //                            wirestr = "WIRE (" & ROW.Item(2) & ")"
      //                        End If
      //                        aset.Tables(0).Rows.Add(sapPlid, HARNESSSYNTH, 1, ROW.Item(0), wirestr, drawingnum, "-", "ADD", "", "", 0, 0, "", "", ROW.Item(1), "", drawingnum & "-" & dsMPRS.Tables(0).Rows(0).Item(3).ToString)
      //                        num92211 += 1
      //                    Loop

      //                    Dim PARTSDS As New DataSet
      //                    PARTSDS = data.getData(("SELECT * FROM TBLREFDESCOMP WHERE REFCOMPPLID ='" & sapPlid & "' AND REFACTION ='ADD'"))
      //                    Dim num22 As Integer = (aset.Tables.Item(0).Rows.Count - 1)
      //                    ' ADD PARTS TO SAP
      //                    source = PARTSDS.Tables.Item(0).[Select]("PARTNUMBER LIKE '%%'")
      //                    Dim numP As Integer = (source.Count() - 1)
      //                    Dim numX As Integer = 0
      //                    Try
      //                        aset.Tables(0).Columns.Add("LOCATION")

      //                    Catch ex As Exception

      //                    End Try

      //                    Do While (numX <= numP)
      //                        ROW = source(numX)
      //                        aset.Tables(0).Rows.Add(sapPlid, HARNESSSYNTH, "", ROW.Item(0), ROW.Item(1) & " (" & ROW.Item(2) & ")", drawingnum, "-", "ADD", "", "", 0, 0, "", "", "", ROW.Item(4), drawingnum & "-" & dsMPRS.Tables(0).Rows(0).Item(3).ToString)
      //                        'aset.Tables(0).Rows.Add(sapPlid, HARNESSSYNTH, ROW.Item(2), ROW.Item(0), ROW.Item(1), drawingnum, "-", "ADD")
      //                        numX += 1
      //                    Loop

      //                    '
      //noharnpr:

      //                Next

      //            End If

      //        Next
      //        aset.AcceptChanges()
      //        aset.Tables(0).DefaultView.Sort = "prtEcp ASC, prtDash ASC"


      //        FOUNDROWS4 = aset.Tables(0).[Select]("PRTECP <>''", "SORT ASC , prtecp asc, prtDash asc")
      //        Dim dtUnique As DataTable
      //        Dim DID As Integer
      //        DID = 9999

      //        ' PLCSDataSet.ReadXmlSchema(Application.StartupPath & "/xmlschema1.xsd")
      //        Dim dssch As New DataSet
      //        dssch.ReadXmlSchema(Application.StartupPath & "/xmlschema2.xsd")
      //        '     dssch.Tables("drawings").Columns.Add("sort")

      //        Try
      //            dssch.Tables(0).Rows.Add(ECP, 0, KCLTV, KCLFROM, KCLENDS)


      //        Catch ex As Exception

      //        End Try
      //        dtUnique = aset.Tables(0).DefaultView.ToTable(True, "prtEcp")
      //        For k = 0 To dtUnique.Rows.Count - 1
      //            Dim NHA As String = ""

      //            ROW = dtUnique(k)
      //            NHA = ROW.Item(0)

      //            dssch.Tables("NHA").Rows.Add(NHA, "B/P", 0, k)
      //            FOUNDROWS4 = aset.Tables(0).[Select]("PRTECP ='" & NHA & "'", "SORT asc")

      //            Dim row2 As DataRow
      //            Dim dwgnum As String = ""
      //            Dim dwgnum2 As String = ""
      //            For l = 0 To FOUNDROWS4.Count - 1
      //                row2 = FOUNDROWS4(l)
      //                dwgnum = row2.Item(1)
      //                If dwgnum = dwgnum2 Then


      //                Else

      //                    If DID = 9999 Then
      //                        DID = 0
      //                    Else
      //                        DID += 1
      //                    End If
      //                    dssch.Tables("DRAWINGS").Rows.Add(dwgnum, "''", "''", "B/P", DID, k)

      //                End If



      //                Dim LOCAT As String = ""
      //                LOCAT = row2.Item(15).ToString

      //                If LOCAT = "" Then

      //                    row2.Item(15) = "-"

      //                End If
      //                If row2.Item(2).ToString.Contains("AR") Then
      //                    row2.Item(2) = "9998"

      //                End If

      //                If dwgnum.Contains("H16DW") Then
      //                    Try
      //                        If row2.Item(4).ToString.Contains("WIRE") Then

      //                            Try
      //                                If row2.Item(14) = "WIRE MARKER" Then
      //                                    row2.Item(14) = "9998"
      //                                End If

      //                                dssch.Tables("WIRES").Rows.Add(row2.Item(3), row2.Item(4), row2.Item(14), "", row2.Item(7), DID)
      //                            Catch ex As Exception

      //                            End Try

      //                        ElseIf row2.Item(3).ToString.StartsWith("W") Then
      //                            If row2.Item(14) = "" Then
      //                                row2.Item(14) = "9998"
      //                            End If
      //                            Try

      //                                dssch.Tables("WIRES").Rows.Add(row2.Item(3), row2.Item(4), row2.Item(14), "", row2.Item(7), DID)
      //                            Catch ex As Exception

      //                            End Try
      //                        Else

      //                            If row2.Item(8) Is DBNull.Value Then
      //                                row2.Item(8) = "-"
      //                            End If
      //                            Dim qtysc As String = ""

      //                            qtysc = row2.Item(4).ToString

      //                            qtysc = qtysc.Substring(qtysc.IndexOf("("))
      //                            qtysc = qtysc.Replace("(", "")
      //                            qtysc = qtysc.Replace(")", "")


      //                            dssch.Tables("PARTS").Rows.Add(row2.Item(3), row2.Item(4), qtysc, row2.Item(15), row2.Item(8), row2.Item(7), DID, k)
      //                        End If


      //                    Catch ex As Exception

      //                    End Try

      //                Else


      //                    dssch.Tables("PARTS").Rows.Add(row2.Item(3), row2.Item(4), row2.Item(2), row2.Item(15), row2.Item(8).trim, row2.Item(7), DID, k)
      //                End If






      //                dwgnum2 = dwgnum

      //            Next



      //        Next


      //        aset.AcceptChanges()

      //        Dim dv As DataView = New DataView(dssch.Tables("WIRES"))
      //        dv.Sort = "WIRE_NO ASC"

      //        Dim DSHJ As DataTable
      //        DSHJ = dv.ToTable.Copy

      //        dssch.Tables("WIRES").Clear()

      //        For H = 0 To DSHJ.Rows.Count - 1
      //            Dim ROEI As DataRow
      //            ROEI = DSHJ.Rows(H)

      //            dssch.Tables("WIRES").Rows.Add(ROEI.Item(0), ROEI.Item(1), ROEI.Item(2), ROEI.Item(3), ROEI.Item(4), ROEI.Item(5))

      //        Next
      //        '  dssch.Tables("WIRES").DefaultView.Sort = ("WIRE_NO ASC")

      //        dssch.AcceptChanges()

      //  dssch.Tables("WIRES").DefaultView.Sort("WIRE_NUM ASC")
      SaveFileDialog Sdialog = new SaveFileDialog { Filter = "xml files (*.xml)|*.xml" };
      Sdialog.FileName = "SAP EXPORT FOR " + cmbTail.Text + " " + ComboBoxEdit1.Text + " TO " + ComboBoxEdit2.Text;


      if ((Sdialog.ShowDialog() == DialogResult.OK)) {

        string fileName = Sdialog.FileName;

        dssch2.WriteXml(fileName);
      }
    }


    private void  // ERROR: Handles clauses are not supported in C#
SimpleButton6_Click(System.Object sender, System.EventArgs e)
    {
      DataSet dsOld = new DataSet();
      DataSet dsNew = new DataSet();
      DataRow dr;
      string err = "";
      System.Data.DataRow drnew;
      DataSet dsc = new DataSet();
      dsOld.ReadXml((System.Windows.Forms.Application.StartupPath + "\\tsold.xml"));
      dsNew.ReadXml((System.Windows.Forms.Application.StartupPath + "\\tsnew.xml"));
      //For Each dr In dsNew.Tables("parts").Rows

      //    Try

      //        Dim foundrows() As Data.DataRow

      //        foundrows = dsOld.Tables("parts").[Select](dr.ItemArray(0).ToString)

      //        drnew = foundrows(0)

      //        dsOld.Tables("PARTS").Rows.Remove(drnew)


      //    Catch ex As Exception
      //        err = ex.ToString
      //    End Try
      //    If err <> "" Then
      //        dsc = dsNew.GetChanges()

      //    End If


        
      //Next



        //JMR -- attempt 1
      /*DataRow[] rowsnotfound = (from rowstb2 in dsNew.Tables["parts"].Rows.OfType<DataRow>()where (dsOld.Tables["parts"].Rows.OfType<DataRow>()DataRowwhere ((rowstb1["TRANSACTION"]) == (rowstb2["TRANSACTION"]) & (rowstb1["DESCRIPTION"]) == (rowstb2["DESCRIPTION"]) & (rowstb1["QTY"]) == (rowstb2["QTY"]) & (rowstb1["PART_NUM"]) == (rowstb2["PART_NUM"])).Count()) == 0).ToArray();//JMR -- changed ToArray to ToArray()
      DataRow[] rowsnotfound3 = (from rowstb2 in dsNew.Tables["parts"].Rows.OfType<DataRow>()where (dsOld.Tables["parts"].Rows.OfType<DataRow>()DataRowwhere ((rowstb1["TRANSACTION"]) == (rowstb2["TRANSACTION"]) & (rowstb1["DESCRIPTION"]) == (rowstb2["DESCRIPTION"]) & (rowstb1["QTY"]) == (rowstb2["QTY"]) & (rowstb1["PART_NUM"]) == (rowstb2["PART_NUM"])).Count()) == 0).ToArray();//JMR -- changed ToArray to ToArray()
      foreach (DataRow row in rowsnotfound) {
        // dsNew.Tables("parts").Rows.Remove(row)
      }
      DataRow[] rowsnotfound2 = (from rowstb2 in dsOld.Tables["parts"].Rows.OfType<DataRow>()where (dsNew.Tables["parts"].Rows.OfType<DataRow>()DataRowwhere ((rowstb1["TRANSACTION"]) == (rowstb2["TRANSACTION"]) & (rowstb1["DESCRIPTION"]) == (rowstb2["DESCRIPTION"]) & (rowstb1["QTY"]) == (rowstb2["QTY"]) & (rowstb1["PART_NUM"]) == (rowstb2["PART_NUM"])).Count()) == 0).ToArray();


      foreach (DataRow row in rowsnotfound2) {
        //dsNew.Tables("parts").Rows.Remove(row)
      }*/

       //JMR -- attempt 2
        /*DataRow[] rowsnotfound = (
    from DataRow rowstb2 in dsNew.Tables["parts"].Rows.OfType<DataRow>()
    where ((
            from DataRow rowstb1 in dsOld.Tables["parts"].Rows.OfType<DataRow>()
            where (rowstb1["TRANSACTION"] == rowstb2["TRANSACTION"]
                && rowstb1["DESCRIPTION"] == rowstb2["DESCRIPTION"]
                && rowstb1["QTY"] == rowstb2["QTY"]
                && rowstb1["PART_NUM"] == rowstb2["PART_NUM"])
            select rowstb1).Count()) == 0).ToArray();

        foreach (DataRow row in rowsnotfound) {
        // dsNew.Tables("parts").Rows.Remove(row)
      }

        DataRow[] rowsnotfound2 = (
    from DataRow rowstb2 in dsOld.Tables["parts"].Rows.OfType<DataRow>()
    where ((
            from DataRow rowstb1 in dsNew.Tables["parts"].Rows.OfType<DataRow>()
            where (rowstb1["TRANSACTION"] == rowstb2["TRANSACTION"]
                && rowstb1["DESCRIPTION"] == rowstb2["DESCRIPTION"]
                && rowstb1["QTY"] == rowstb2["QTY"]
                && rowstb1["PART_NUM"] == rowstb2["PART_NUM"])
            select rowstb1).Count()) == 0).ToArray();*/

        //JMR -- attempt 3
      IEnumerable<DataRow> newRows = dsNew.Tables["parts"].Rows.OfType<DataRow>();
      IEnumerable<DataRow> oldRows = dsOld.Tables["parts"].Rows.OfType<DataRow>();

      DataRow[] rowsnotfound = newRows
      .GroupJoin(oldRows,
          o => new
          {
              Transaction = o.Field<int>("TRANSACTION"),
              Description = o.Field<string>("DESCRIPTION"),
              Quantity = o.Field<int>("QTY"),
              PartNumber = o.Field<string>("PART_NUM")
          },
          i => new
          {
              Transaction = i.Field<int>("TRANSACTION"),
              Description = i.Field<string>("DESCRIPTION"),
              Quantity = i.Field<int>("QTY"),
              PartNumber = i.Field<string>("PART_NUM")
          },
          (o, i) => new { NewRow = o, OldRows = i })
      .SelectMany(g => g.OldRows.DefaultIfEmpty(), (g, oldRow) => oldRow == null ? g.NewRow : null)
      .Where(r => r != null)
      .ToArray();

      foreach (DataRow row in rowsnotfound)
      {
          // dsNew.Tables("parts").Rows.Remove(row)
      }

      newRows = dsNew.Tables["parts"].Rows.OfType<DataRow>();
      oldRows = dsOld.Tables["parts"].Rows.OfType<DataRow>();

      DataRow[] rowsnotfound2 = oldRows
      .GroupJoin(newRows,
          o => new
          {
              Transaction = o.Field<int>("TRANSACTION"),
              Description = o.Field<string>("DESCRIPTION"),
              Quantity = o.Field<int>("QTY"),
              PartNumber = o.Field<string>("PART_NUM")
          },
          i => new
          {
              Transaction = i.Field<int>("TRANSACTION"),
              Description = i.Field<string>("DESCRIPTION"),
              Quantity = i.Field<int>("QTY"),
              PartNumber = i.Field<string>("PART_NUM")
          },
          (o, i) => new { OldRow = o, NewRows = i })
      .SelectMany(g => g.NewRows.DefaultIfEmpty(), (g, oldRow) => oldRow == null ? g.OldRow : null)
      .Where(r => r != null)
      .ToArray();

    }


    private void  // ERROR: Handles clauses are not supported in C#
cmbECP_SelectedIndexChanged(System.Object sender, System.EventArgs e)
    {

    }

    private void GridControl1_Click(object sender, EventArgs e)
    {

    }

      public frmMKPL()
    {
        InitializeComponent();
    }
  }
}

